Java题,大佬们,求助

题:使用while循环完成输出所有三位数中能被8整除的数,每个数字之间以空格间隔开,每输出10个数字换行。

效果图:

public static void main(String[] args) {
int i = 100;
int j = 0;
while (i<999){
if (i % 8 == 0){
System.out.print(i+" ");
j++;
}
if (j == 10){
j = 0;
System.out.println();
}
i++;
}
}

运行结果

望采纳,谢谢。追问

多谢大佬,已关注,有事私聊你

追答

嗯,好的

温馨提示:内容为网友见解,仅供参考
第1个回答  2020-03-26
public static void main(String[] args) {
int i=100;
int count=0; //用于计算输出数的个数,以便换行
while(i<=1000) {
if(i%8==0) { //判断i是否能被8整除
System.out.print(i+"\t");//如果能被8整除,输出,并且空几格
count++;
}
i++; //i自增,以便进行下一个数的判断
if(count%10==0) { //如果输出了10个数,则可以换行
System.out.println();
}
}
}
相似回答