如何用java代码在命令行打出菱形大写字母
作者:
吃盖浇饭 | 来源:发表于
2018-06-16 08:51 被阅读2次
菱形
System.out.println("1.第二题");
System.out.println();
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m - i; j++) {
System.out.print(" ");
}
char charNum1 = 'A';
int k = 1;
char strM = 'A';
for (char str = charNum1; k <= 2 * i - 1; str++) {
if(k<=i){
System.out.print(str);
strM = str;
}else{
System.out.print(--strM);
}
k++;
}
System.out.println();
Thread.sleep(100);
}
for (int i = 1; i < m; i++) {
for (int j = 1; j <= i; j++) {
System.out.print(" ");
}
char charNum1 = 'A';
int k = 1;
char strM = 'A';
for (char str = charNum1; k <= 2 * (m - i) - 1; str++) {
int num = m - i;
if(k < num + 1 ){
System.out.print(str);
strM = str;
}else{
System.out.print(--strM);
}
k++;
}
System.out.println();
Thread.sleep(100);
}
System.out.println();
本文标题:如何用java代码在命令行打出菱形大写字母
本文链接:https://www.haomeiwen.com/subject/igwveftx.html
网友评论