For Loop

Simple For loop Example

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

11 Comments

  • for (int i=10;i>=1;i–){
    for (int j=1;j<=i;j++){
    System.out.print(” “);
    }for (int j=10;j>=i;j–){
    System.out.print(“*”);
    }for (int l=9;l>=i;l–){
    System.out.print(“*”);
    }System.out.println();
    }

    for (int i=8;i>=0;i–){
    for (int j=9;j>=i;j–){
    System.out.print(” “);
    }for (int k=0;k<=i;k++){
    System.out.print(“*”);
    }for (int j=1;j<=i;j++){
    System.out.print(“*”);
    }System.out.println();
    }
    }
    }

    • for(int i=0;i<=8;i++)

      {

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

      {

      System.out.print(“*”);

      }

      System.out.println();

      }

      for(int i=8;i>=0;i–)

      {

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

      {

      System.out.print(“*”);

      }

      System.out.println();

      }

  • While applying a for loop i am getting the output elements one below the other . What should I do to get the out put in a single row?

Sponsors

Facebook Fans