close

java練習:for迴圈

一、列出所得到的數字(0-10)

for(int a=0 ; a<=10 ; a++) {

System.out.print(a+" ");

}

System.out.println();

 

二、 同樣的東西跑幾次

 

for(int b=1 ; b<=3 ; b++) {

System.out.print("a");

}

 

 

三、得到2x1=2 3x1=3 4x1=4

 

System.out.println("三、");

for(int c=2 ; c<=4 ; c++) {

System.out.println(c+"*1="+c);

}

 

四、九九乘法表

 

for(int d = 1 ; d<=9 ;d++) {

for(int f =1 ; f<=9 ; f++) {

System.out.print(d+"x"+f+"="+d*f+"\t");

}

System.out.println();

}

 

五、畫出

10 9 8 7 6 5 4 3 2 1 

10 9 8 7 6 5 4 3 2 

10 9 8 7 6 5 4 3 

10 9 8 7 6 5 4 

10 9 8 7 6 5 

10 9 8 7 6 

10 9 8 7 

10 9 8 

10 9 

10 

for(int e=1 ; e<=10; e++) {

for(int f=10 ; f>=e ; f--) {

System.out.print(f+" ");

}

System.out.println();

}

arrow
arrow

    ivy 發表在 痞客邦 留言(0) 人氣()