文章目录
1、正等腰三角形
//正等腰三角形import java.util.Scanner;public class Demo1 {public static void main(String[] args) {// TODO Auto-generated method stub Scanner scan = new Scanner(System.in); System.out.println("输入要打印的行数:"); int n = scan.nextInt(); for (int i = 1; i <=n; i++) { //打印空格 for (int j = 0; j < n-i; j++) { System.out.print(" ");} //打印* for (int k = 0; k < 2*i-1; k++) {System.out.print("*");} //打印完一行,进行换行 System.out.println();}}}
运行结果:
2、倒等腰三角形
//打印倒三角形import java.util.Scanner;public class Demo2 {public static void main(String[]
来源地址:https://blog.csdn.net/weixin_54620953/article/details/129536553