输入一个大写的英文字母,输出空心的字母金字塔。
输入格式:
一个大写英文字母。
输出格式:
一个空心的大写英文字母金字塔,其中第1层的“A”在第1行的第40列,列从1开始计数。
输入样例:
E
输出样例:
A
B B
C C
D D
EEEEEEEEE
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
String str=s.next();//定义字符串
char c = str.charAt(0);//取字符串的第一个字符
int x = c -'A' + 1;//将该字符转换为对应的ascll码
int cnt = 40;
char ch = 'A';
int num = 0;
int m = x;
x = x * 2 + 1;
for (int i = x / 2 + 1; i >=3 ; i--) {
for (int j = 1; j < cnt; j ++)
System.out.print(" ");
for (int j = 1; j <= x; j ++) {
if (i == j || j == x + 1 -i)
System.out.print(ch);
else if(j > i && j <= x + 1 - i){
System.out.print(" ");
}
}
ch++;
cnt--;
System.out.println();
}
cnt-=2;
for (int i = 0; i <= cnt; i++)
System.out.print(" ");
for (int i = 0; i <= 2 * m - 2; i++)
System.out.print(ch);
}
}