Java 如何使用for循环复制char变量

Java 如何使用for循环复制char变量,java,loops,for-loop,character,Java,Loops,For Loop,Character,所以我想知道如何使用for循环复制字母c。我用*符号做了这个,但似乎不能用字母c。我使用IBIO获取输入。我需要知道如何以与*相同的方式复制c。当我运行代码时,c只打印一次。为什么会这样?请帮我修一下 public class Methods { public static void main (String args[]) { new Methods (); } public quadMethods () { p

所以我想知道如何使用for循环复制字母c。我用*符号做了这个,但似乎不能用字母c。我使用IBIO获取输入。我需要知道如何以与*相同的方式复制c。当我运行代码时,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 ("");
    }
}
公共类方法
{
公共静态void main(字符串参数[])
{
新方法();
}
公共方法()
{
printNStars(5);
printNChars(6,'q');
}
公共无效打印字符串(int n)
{//在屏幕上连续打印“n”个星星
n=IBIO.inputInt(“为'n':'输入一个数字”);

对于(int i=0;i您有几个问题。一个是两个循环的迭代次数:

public void printNStars (int n)
{
    n = IBIO.inputInt ("Enter a number for 'n': ");
    for (int i = 0; i <= n; i++)
        System.out.print ("*");
    System.out.println ("");
}
第二个问题是另一个循环中的分号:

for (int i = 0; i <= n; i++);

它是由
for
循环后的一个流氓
引起的。更改
for(int i=0;i)这个问题是由一个无法再复制的问题或一个简单的印刷错误引起的。虽然这里可能有类似的问题,但这个问题是以一种不太可能帮助未来读者的方式解决的。这通常可以通过确定和仔细检查复制问题所需的最短程序来避免m发帖前。谢谢你的详细回答。但是我在运行程序时只打印了6个c。这是为什么?呃…因为你叫它,要求6个:
printNChars(6,'q');
?那么如果你使用我的
printntars
的正确版本并称它为
printntars(5),我为什么不打印5颗星呢
那么你应该得到五颗星了,不管怎样,再次感谢
for (int i = 0; i <= n; i++);
public void printNChars (int n, char c)
{
    for (int i = 0; i < n; i++)
    {
        System.out.print (c);
    }
    System.out.println ("");
}