【发布时间】:2016-02-21 17:33:17
【问题描述】:
这就是问题所在:
创建一个 IsoTri 应用程序,提示用户输入等腰三角形的大小,然后显示具有那么多线条的三角形。
示例:4
*
**
***
****
***
**
*
IsoTri 应用程序代码应包含printChar(int n, char ch) 方法。此方法会将 ch 打印到屏幕 n 次。
这是我目前所拥有的:
public static void main(String[] args) {
int n = getInt("Give a number: ");
char c = '*';
printChar(n, c);
}
public static int getInt(String prompt) {
int input;
System.out.print(prompt);
input = console.nextInt();
return input;
}
public static void printChar(int n, char c) {
for (int i = n; i > 0; i--) {
System.out.println(c);
}
}
我不知道如何让它打印三角形。任何帮助表示赞赏。
【问题讨论】:
-
提示:例如打印 *,然后 **,然后 ***,然后 **,然后 *
-
@KumarSaurabh 略有不同,他必须实现
printChar(int n, char ch)
标签: java loops for-loop methods char