Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
嵌套循环直角三角形java_Java_Loops_Nested - Fatal编程技术网

嵌套循环直角三角形java

嵌套循环直角三角形java,java,loops,nested,Java,Loops,Nested,因此,我想使用嵌套循环在java中创建一个数字直角三角形,我创建了以下内容: public class nestedloop { public nestedloop() { loop(); } public static void main(String [] args) { new nestedloop(); } public static void loop() { Syste

因此,我想使用嵌套循环在java中创建一个数字直角三角形,我创建了以下内容:

public class nestedloop
{
    public nestedloop()
    {
       loop();   
    }

    public static void main(String [] args)
    {
       new nestedloop();
    }

    public static void loop()
    {

      System.out.println(" Enter a number ");
      int n= IBIO.inputInt();

      for (int i = 1; i <=n; i++) {
        for (int j = 1; j <= i; j++) {
          System.out.print("*");
        }
        System.out.println();
      }

    }

}
公共类嵌套循环
{
公共嵌套循环()
{
loop();
}
公共静态void main(字符串[]args)
{
新nestedloop();
}
公共静态void循环()
{
System.out.println(“输入一个数字”);
int n=IBIO.inputInt();
对于(int i=1;i只需创建一个计数器:

public static void loop(){

    System.out.println(" Enter a number ");
    int n= IBIO.inputInt();
    int counter = 0;
    for (int i = 1; i <=n; i++) {
        for (int j = 1; j <= i; j++) {
            System.out.println(++counter);
        }
    }
}
publicstaticvoidloop(){
System.out.println(“输入一个数字”);
int n=IBIO.inputInt();
int计数器=0;
对于(int i=1;i只需创建一个计数器:

public static void loop(){

    System.out.println(" Enter a number ");
    int n= IBIO.inputInt();
    int counter = 0;
    for (int i = 1; i <=n; i++) {
        for (int j = 1; j <= i; j++) {
            System.out.println(++counter);
        }
    }
}
publicstaticvoidloop(){
System.out.println(“输入一个数字”);
int n=IBIO.inputInt();
int计数器=0;

对于(int i=1;i),您显然希望在此处放置一个计数器,其值随每次打印而增加。显示您迄今为止尝试的内容(即使失败)您显然希望在此处放置一个计数器,其值随每次打印而增加。显示您迄今为止尝试的内容(即使失败)我不熟悉编码,所以我没有主动权使用我以前在代码中学到的东西将你的
System.out.print
更改为
System.out.println
,并在内部for循环后删除
System.out.println
。我不熟悉编码,所以我没有主动权使用我以前在代码中学到的东西您的
System.out.print
System.out.println
并删除内部for循环后的
System.out.println
。。。