1个回答
展开全部
import java.util.Scanner;
public class Demo {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("请输入金字塔的层数:");
int x = reader.nextInt();
for (int i = 1; i < x; i++) {
for (int j = 1; j < x - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");// 打印星
}
System.out.println();// 换行
}
}
}
public class Demo {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("请输入金字塔的层数:");
int x = reader.nextInt();
for (int i = 1; i < x; i++) {
for (int j = 1; j < x - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");// 打印星
}
System.out.println();// 换行
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询