第九章 循环结构进阶
英语新识:
triangle 三角形 circle 圆圈 diamond 菱形 password 口令 row 行
语法新知:
while与while的循环嵌套:
do-while 与do-while循环嵌套
for与for循环嵌套:
while 与for循环嵌套
矩形的打印:
public class RTriAngle{
public static void main (String [] args ){
System.out.println(" 打印矩形");
for(int i=1; i<=5; i++){
for (int j=1;j<=5;j++){
System.out.print("*");
}
System.out.print("\n");
}
}
}
九九乘法表:
public class RTriAngle{
public static void main (String [] args ){
System.out.println(" 九九乘法表:");
for(int i=1; i<=9; i++){
for (int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+j*i+" ");
}
System.out.print("\n");
}
}
}
等腰三角:
public class RTriAngle{
public static void main (String [] args ){
System.out.println(" 打印等腰三角");
for(int i=1; i<=5; i++){
for (int j=1;j<=5;j++){
System.out.print(" ");
}
for (int k=1; k<=(2*i)-1; k++){
System.out.print("*");
}
System.out.println("\n");
}
}
}
菱形的打印:
int lay;
lay=7;
for (int m=1; m<=(lay+1)/2 ;m++){
for (int b =1; b<=(lay+1)/2-m;b++){
System.out.print("\n");
}
for(int c=1;c<=m*2-1;c++){
System.out.print("*");
}
System.out.println();
}
for(int d =(lay+1)/2-1;d>=1;d--){
for (int b=1; b<=(lay +1)/2-d;b++){
System.out.print("\n");
for(int c=(lay+1)/-d;c<=(lay+1)/2-2+d;c++){
System.out.print("*");
}
System.out.println();
}
}
}