(1) for循環實現
/* print()默認是不換行的
println()默認是換行的
"\t"是空格
"\n" 換行符
*/
public static void main(String[] args) {
for(int i = 0; i<=1000; i ++ ){
if (i%5==0){//判斷i是否能被5整除
System.out.print(i+"\t");//前兩個數之間用空格"\t"隔開,不換行
}
if (i%(5*3)==0){//能被5整除的第三個數,到這里輸出三個數之后換行
System.out.println();
// System.out.print("\n");
}
}

(2) while循環實現
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();
}
}
}
(3)whlie循環另一種(不提倡)
public static void main(String[] args) {
int i = 1;
while(i<=1000){
if(i%5==0 && i%(5*3)!=0){//這里若不加i%(5*3)!=0,會產生多余的能被5整除的數
System.out.print(i+"\t");
}
if (i%(5*3)==0){
System.out.println(i);
}
i++;
}
}