把下列代码保存为Oushu.java,编译运行之
------------------------------------------
public class Oushu {
public static void main (String[] args) {
for (int i = 1; i<=100; i++){
if(i%2==0)
{
System.out.print(i+"\t");
if(i%5==0)
System.out.println("");
}
}
}
}
public class T {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
if (i % 2 == 0) {
System.out.printf("%3d",i);
if (i % 5 == 0)
System.out.println();
}
}
}
}
//按照需求,这个效率最高了,没有用到求余运算!
public class T {
public static void main(String[] args) {
for(int i=2,j=1;i<=100;i=i+2,j++){
System.out.print(i+"\t");
if(j==5){
System.out.println();
j=0;
}
}
}
}
int j=0;
for(int i=1;i<=100;i++){
if(j==5){
System.out.println("");
j=0;
}
if(i%2==0){
System.out.print(i);
j++;
}
}