用while循环写输出1到1000以内能被5整除的数的小程序,要求每三个一行输出代码如下int c=1;int count=0;while(c

来源:学生作业学帮网 编辑:学帮网 时间:2024/06/04 05:12:11

用while循环写输出1到1000以内能被5整除的数的小程序,要求每三个一行输出
代码如下
int c=1;
int count=0;
while(c

count == 3 时会打印两遍

可以改成:

if ( count == 3 ) {
    System.out.println( c + " " );
    count = 0;
}
else {
    System.out.print( c + " " );
}
c++;