我想显示由星号组成的字母A
。首先,程序将询问字母的大小,然后根据给定的大小将字母缩放到该大小。
这是我到目前为止所拥有的,但我不确定我做错了什么。如您所见,它只打印一行。任何帮助都会很棒。
代码:
import java.util.Scanner;
public class Problem7 {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in);
int input, size, i;
System.out.print("Enter a size: ");
input = kbd.nextInt();
while (input <= 1) {
System.out.print("Enter a size: ");
input = kbd.nextInt();
}
for (int col = 0; col < input; col++) {
for (int row = 0; row < input; row++) {
if (col == 1 || col == input || row == col)
System.out.print("*");
else
System.out.print(" ");
}
}
}
}
结果:
Enter a size: 5
* ***** * * *
最佳答案
如果你想要一个新行,只需使用:
System.out.print("\n");
关于java - 显示由星号组成的字母的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31169767/