正直角三角形:
package com.Summer_0416.cn; public class Test_Method08 { public static void main(String[] args) { for (int i = 0; i < 5; i++) {//外层循环1,2,3,4,5 for (int j = 0; j <=i; j++) {//内层循环1,2,3,4,5 System.out.print("* "); } System.out.println(); } } }
反三角形:
package com.Summer_0416.cn; public class Test_Method09 { public static void main(String[] args) { for (int i = 0; i < 5; i++) {//外层 循环 1,2,3,4,5 for (int j = 5; j > i; j--) {//内层循环5,4,3,2,1 System.out.print("* "); } System.out.println(); } } }