打印三角形
package com.mike.struct;
import java.util.Scanner;
public class TestDemo {
public static void main(String[] args) {
//打印三角形5行
System.out.println("输入需要打印三角形的层数:");
Scanner scanner = new Scanner(System.in);
int height = scanner.nextInt();
//四个for循环
for(int i=1;i<=height;i++){
for(int j=height;j>=i;j--){
System.out.print(" ");
}
for(int j=1;j<=i;j++){
System. out. print("*");
}
for(int j=1;j<i;j++){
System. out. print("*");
}
System.out.println();
}
//用三个for循环
System.out.println("=================================");
for(int i = 1;i < height+1;i++) {
for(int j = 1;j <= height-i;j++) {
System.out.print(" ");
}
for(int j = 1;j <= 2*i-1;j++) {
System.out.print("*");
}
System.out.println();
}
scanner.close();
}
}