用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个
for输出
public static void main(String[] args) {
// 用while或for循环输出1-1000之间能被5整除的数,并且每行输出3个
for (int i = 1; i < 1000; i++) {
if (i%5==0){//跳格
System.out.print(i+"\t");
}
if (i%(5*3)==0){//换行
System.out.println();
//System.out.printl("\n");
}
}
//println 输出完会换行
//printl 输出完不会换行
}
while输出
public class Test04 {
public static void main(String[] args) {
int i=1;
int count=0; //用于计算输出数的个数,以便换行
while(i<=1000) {
if(i%5==0) { //判断i是否能被5整除
System.out.print(i+"\t");//如果能被5整除,输出,并且空几格
count++;
}
i++; //i自增,以便进行下一个数的判断
if(count%3==0) { //如果输出了三个数,则可以换行
System.out.println();
}
}
}
}