1.输出一个直角三角形
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);System.out.println("请输入直角三角形的高度:");
int height = sc.nextInt();
for (int i = 0; i < height; i++) {//控制*的行数
for (int j = 0; j <= i; j++) {//控制*的数量
System.out.print("*");
}
System.out.println();
}
}
2.//核心在于内层循环的条件
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入三角形的高度:");
int height = sc.nextInt();
for (int i = 0; i < height; i++) {
for (int j = 0; j< 2 * i + 1; j++) {
System.out.print("*");
}
System.out.println();
}
}
3.//倒立的直角三角形
public class T4 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入倒立的直角三角形的高:");
int height = sc.nextInt();
for (int i = 0; i < height; i++) {
for (int j = 0; j <height-i; j++) {
System.out.print("*");
}
System.out.println();
}
}