【发布时间】:2016-03-18 22:22:20
【问题描述】:
所以我想知道如何使用 for 循环复制字母 c。我已经使用 * 符号完成了此操作,但似乎无法使其与字母 c 一起使用。我使用 IBIO 来获取输入。我需要知道如何以与 *.当我运行代码时, c 只打印一次。为什么是这样?请帮我解决它。
public class Methods
{
public static void main (String args[])
{
new Methods ();
}
public quadMethods ()
{
printNStars (5);
printNChars (6, 'q');
}
public void printNStars (int n)
{ //prints 'n' stars on the screen in a row
n = IBIO.inputInt ("Enter a number for 'n': ");
for (int i = 0; i <= n; i++)
System.out.print ("*");
System.out.println ("");
}
public void printNChars (int n, char c)
{ //prints 'n' of character c on the screen in a row
for (int i = 0; i <= n; i++);
{
System.out.print ("c");
}
System.out.println ("");
}
}
【问题讨论】:
-
这是在
for循环之后由流氓;引起的。 -
将
for (int i = 0; i <= n; i++)更改为for (int i = 0; i <= n; i++){ -
这个问题是由无法再复制的问题或简单的印刷错误引起的。虽然类似的问题可能是这里的主题,但这个问题的解决方式不太可能帮助未来的读者。这通常可以通过在发布之前确定并仔细检查重现问题所需的最短程序来避免。
标签: java loops for-loop character