
用while循环写字母金字塔。从键盘输入一个大写英文字母,输入对应的字母金字塔。 10
1个回答
展开全部
public static void main(String[] args) {
System.out.println("请输入字母:");
Scanner sc = new Scanner(System.in);
String s = sc.nextLine(); // s是输入的字母
int i = 10;//金字塔行数
for (int x = 1; x <= i; x++) {
for (int y = i - x; y >= 0; y--) {
System.out.print(" ");
}
for (int a = 1; a <= (2 * x - 1); a++) {
System.out.print(s);
}
System.out.println("");//专门负责换行
}
}
望采纳。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询