用for循环和while循环输出1-1000内能被5整除的数,每行三个。
/**
*阶段一第四章作业
* for循环输出1-1000之间能被5整除的数,每行3个。
*while循环输出1-1000之间能被5整除的数,每行3个。
*/
public class Workfor {
public static void main(String[] args) {
int a=1;
int i=1;
for ( i =1 ;i<=1000;i++){
if (i%5==0){
System.out.print(i+"\t");
a++;
if(a>3){
System.out.println("");
a=1;
}
}
}
//while循环
while(a<=1000){
if (a%5 == 0){
if(i<=3)
System.out.print(a+"\t");
i++;
if(i>3){
System.out.println();
i=1;
}
}
a++;
}
}
}