标签:style dem ++ ring div str pack stat 输出
1.嵌套循环:将一个循环结构嵌套在另一个循环结构中。例如A在B中循环
2.外层循环:B
内层循环: A
3.假设外层循环了M次,内层循环了N次,一共循环了M*N次
4.外层控制行数,内层控制个数
package struct; public class demo21 { public static void main(String[] args) { //输出五行星,每行四个 for (int i = 1; i <= 5; i++) { for (int i1 = 1; i1 <=4; i1++) { System.out.print("*"); } System.out.println(); } } }
package struct; public class demo22 { public static void main(String[] args) { //输出一个菱形 for (int i = 1; i <5; i++) { for (int j = 1; j <=6-i; j++) { System.out.print(" "); } for (int i1 = 1; i1 <i; i1++) { System.out.print("*"); } for (int i1 = 1; i1 <=i; i1++) { System.out.print("*"); } System.out.println(); } for (int i = 1; i <=5; i++) { for (int i1 =1 ; i1 <=i; i1++) { System.out.print(" "); } for (int i1 = 1; i1 < 6-i; i1++) { System.out.print("*"); } for (int i1 = 1; i1 <=6-i; i1++) { System.out.print("*"); } System.out.println(); } } }
标签:style dem ++ ring div str pack stat 输出
原文地址:https://www.cnblogs.com/huzh123/p/13513851.html