方法一.
//能被5整除的数,每隔三个,是15的倍数
public static void main(String[] args){
for(int i = 1; i <= 1000; i++){
if(i % 5 == 0){
System.out.print(i+"\t")
}
if(i % 15 == 0){
System.out.println();
}
}
方法二.
public static void main(String[] args){
int count = 0; //count用来监测每行有几个数,每增加一个数时,count加1,当有三个时,换行,count变为零
for(int i = 1; i <= 1000; i++){
if(i % 5 == 0){
System.out.print(i+"\t")
count += 1;
}
if(count == 3){
System.out.println();
count = 0;
}
}
}