【发布时间】:2012-02-08 06:52:33
【问题描述】:
我在完成这个程序时遇到了困难。我正在尝试制作一个创建星号的程序,然后将其变成三角形。
这是我已经拥有的。
public class 12345 {
public static void main(String[] args) {
int n = 0;
int spaces = n;
int ast;
System.out.println("Please enter a number from 1 - 50 and I will draw a triangle with these *");
Scanner keyboard = new Scanner(System.in);
n = keyboard.nextInt();
for (int i = 0; i < n; i++) {
ast = 2 * i + 1;
for (int j = 1; j <= spaces + ast; j++) {
if (j <= spaces)
System.out.print(' ');
else
System.out.print('*');
}
System.out.println();
spaces--;
}
}
}
它正在创建星号,但我如何才能在它们形成三角形的地方继续它们......所以它们会随着它们变大,然后变小......
提前感谢您!
【问题讨论】:
-
允许以数字开头的类名?????
-
你想做菱形的结构吗?
-
从创建
Right angled triangle开始。
标签: java whitespace drjava