Eclipse 如何在控制台中打印该图形?
我想在控制台中打印:Eclipse 如何在控制台中打印该图形?,eclipse,Eclipse,我想在控制台中打印: * ** *** ** * 所以,我的代码是: Scanner input = new Scanner(System.in); int n = input.nextInt(); char c = '*'; if (1 < n && n < 20) { for (int row = 1; row <= n; row++) { for (
*
**
***
**
*
所以,我的代码是:
Scanner input = new Scanner(System.in);
int n = input.nextInt();
char c = '*';
if (1 < n && n < 20) {
for (int row = 1; row <= n; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(c);
}
System.out.println();
}
扫描仪输入=新扫描仪(System.in);
int n=input.nextInt();
字符c='*';
如果(1
System.out.print("* **");
如果我的答案不是您所期望的,那么请提供更多信息。您的实际问题是什么。如果n
是您的“*”
长度,请参见下面的代码:
if (1 < n && n < 20) {
for (int row = 1; row <= n; row++) {
for (int col = 1; col <= row; col++) {
System.out.print(c);
}
System.out.println();
}
for (int row =1; row <= n; row++) {
for (int col = n-row; col >0 ; col--) {
System.out.print(c);
}
System.out.println();
}
}
if(1 对于(int row=1;row您期望的输出是什么?或者更新输出模式(图)。什么值有n?为什么编写代码那么困难?对不起,我的问题是错误的-图的大小是n(您在控制台中输入的,int n=input.nextInt();这里是n=3,tksOr如果n是您的“*”长度,在代码下面-这一个很有效。tks!