java给定字母N打印大写字母阵
时间: 2023-12-17 07:03:56 浏览: 70
好的,下面是一个基于Java的解决方案,可以根据输入的字母N打印出相应的大写字母阵:
```
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
char ch = scanner.next().charAt(0);
int n = ch - 'A' + 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print(ch);
}
System.out.println();
}
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print(ch);
}
System.out.println();
}
scanner.close();
}
}
```
使用时,输入一个大写字母N,程序会输出相应的大写字母阵。例如,输入字母E,输出如下:
```
A
BBB
CCCCC
DDDDDDD
EEEEEEEEE
DDDDDDD
CCCCC
BBB
A
```
阅读全文