打印等腰三角形:
public class Demo01 {
public static void main(String[] args) {
//打印等腰三角形
// *
// ***
// *****
// *******
// *********
for (int i = 1; i <= 5; i++) {
for (int j = 5; 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();
}
}
}
打印倒直角三角形:
import java.util.Scanner;标签:int,流程,打印,System,print,三角形,public,out From: https://www.cnblogs.com/123456dh/p/17089882.html
public class Demo02 {
//打印倒直角三角形
// *****
// ****
// ***
// **
// *
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j < i; j++){
System.out.print(" ");
}
for (int j = 5; j >= i; j--){
System.out.print("*");
}
System.out.println();
}
}
}