Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Nested For Loop in java?


Nested For Loop means we will write more than one for loop using nested sequence.it has a collection of inner for loop and outer for loop,
The outer for loop will execute once but the inner for loop will continuously be executed.

for(init;condition;increment)
{
    for(init;condition;increment)
     {
         System.out.print("statement");
    }
    System.out.println();

}

WAP to print the following statement?

1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
............................................................................................

A a B b C
A a B b
A a B
A a
A
..................................................................................................


A solution to This Program:


class Pattern
{
   public static void main(String args[])
   {
     for(int i=1;i<=5;i++)
     {
         int asc=65;
         for(int j=1;j<=6-i;j++)
          {
              if(j%2!=0)
              System.out.print((char)asc+" ");
              else
              {
              System.out.print((char)(asc+32)+" ");
              asc++;
              } 

          }
         System.out.println();   
         

     }       
   }


}

............................................................................................................................................

1 2 3 4 5
5 4 3 2
1 2 3
5 4
1
.......................................................................


class Pattern
{
   public static void main(String args[])
   {
     for(int i=1;i<=5;i++)
     {
       
         for(int j=1;j<=6-i;j++)
          {
              if(i%2!=0)
              System.out.print(j+" ");
              else
              {
              System.out.print((6-j)+" ");
           
              } 

          }
         System.out.println();   
         

     }       
   }


}

.....................................................................................................................................................

ASSIGNMENT:-

1 0 0 1 0
1 0 0 1
1 0 0
1 0
1
.................................................................................

A B C D E
    B C D E
        C D E
            D E
                E
.........................................................................................

             8
     8      8     8
8   8     8      8    8
     8     8      8
            8

................................................................................................









37 Comments

POST Answer of Questions and ASK to Doubt

  1. 1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1
    ............................................................................................

    class nestedloop
    {
    public static void main(String[]arg)
    {
    for(int i=5; i>=1; i--)
    {
    for(int j=1; j<=i; j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  2. 1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1
    .......................................................................

    class loop
    {
    public static void main(String[]arg)
    {
    for(int i=5; i>=1; i--)
    {
    for(int j=1; j<=i; j++)
    {
    if(i%2!=0)
    System.out.print(j);
    else
    System.out.print(6-j);

    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  3. A B C D E
    B C D E
    C D E
    D E
    E
    ---------------------------------------------------------
    class loop
    {
    public static void main(String[]arg)
    {
    int c=0;
    for(int i=65; i<=69; i++)
    {
    for(int j=i; j<=69; j++)
    {
    System.out.print((char)j);
    }
    System.out.println();
    c++;

    for(int k=1; k<=c;k++)
    {
    System.out.print(" ");
    }
    }
    }
    }

    ReplyDelete
  4. public class Main
    {
    public static void main(String[] args)
    {
    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {

    System.out.print(j);
    }

    System.out.println();
    }
    }
    }

    ReplyDelete



  5. public class Main
    {
    public static void main(String[] args)
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {

    System.out.print(j);
    }

    System.out.println();
    }
    }

    ReplyDelete
  6. 11
    22
    333
    444
    55555
    {
    public static void main(String[] args)
    {
    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=i;j++)
    {

    System.out.print(i);
    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  7. 54321
    4321
    321
    21
    1
    public class Main
    {
    public static void main(String[] args) {
    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=i;j>=1;j--)
    {
    System.out.print(j);

    }


    System.out.println();
    }
    }
    }

    ReplyDelete
  8. 55555
    4444
    333
    22
    1

    public class Main
    {
    public static void main(String[] args) {
    int i,j;
    for(i=5;i>=1;i--)
    {
    for(j=1;j<=i;j++)
    {
    System.out.print(i);

    }


    System.out.println();
    }
    }
    }

    ReplyDelete
  9. /******************************************************************************

    Online Java Compiler.
    Code, Compile, Run and Debug java program online.
    Write your code in this editor and press "Run" button to execute it.

    *******************************************************************************/

    public class Main
    {
    public static void main(String arg[])
    {
    for(int i=1;i<=5;i++)
    {


    for(int k=5;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=2*i-1;j++)
    {
    System.out.print("*");
    }



    System.out.println();
    }
    for(int i=5;i>=1;i--)
    {


    for(int k=5;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=2*i-1;j++)
    {
    System.out.print("*");
    }

    System.out.println();
    }
    }
    }



    \\mayur yadav||||||||||||||||||||||||||||||||||||||||||||||||||||

    ReplyDelete
  10. /******************************************************************************//MAyur YaDAV

    Online Java Compiler.
    Code, Compile, Run and Debug java program online.
    Write your code in this editor and press "Run" button to execute it.

    *******************************************************************************/

    public class Hello
    {
    public static void main(String arg[])
    {
    for(int i=1;i<=6;i++)
    {


    for(int k=5;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=2*i-1;j++)
    {
    System.out.print("\uD83D\uDC7D");

    }
    System.out.println();
    }

    for(int i=5;i>=1;i--)
    {
    for(int k=5;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=2*i-1;j++)
    {
    System.out.print("\uD83D\uDC7D");

    }

    System.out.println();
    }
    }
    }

    ReplyDelete
  11. 54321
    4321
    321
    21
    1




    class Nestedloop1
    {
    public static void main(String[]arg)
    {
    for(int i=1; i<=5; i++)
    {
    for(int j=5; j>=i; j--)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  12. class Star1
    {
    public static void main(String[]args)
    {
    for(int i=1;i<=4;i++)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print("*");
    }
    System.out.println();
    }
    for(int i=1;i<=4;i++)
    {
    for(int j=4;j>=i;j--)
    {
    System.out.print("*");
    }
    System.out.println();
    }




    }
    }

    -------------------------------------------------------

    *
    **
    ***
    ****
    ***
    **
    *

    ReplyDelete
  13. class Star2
    {
    public static void main(String[]args)
    {
    for(int i=1;i<=4;i++)
    {
    for(int j=3;j>=i;j--)
    {
    System.out.print(" ");
    }
    for(int k=1;k<=i;k++)
    {
    System.out.print("*");
    }
    System.out.println();
    }

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




    }
    }


    -----------------------------------------------------------


    *
    **
    ***
    ****
    ***
    **
    *

    ReplyDelete
  14. class Diamond
    {
    public static void main(String[]args)
    {
    for(int i=1;i<=4;i++)
    {
    for(int j=3;j>=i;j--)
    {
    System.out.print(" ");
    }
    for(int k=1;k<=i;k++)
    {
    System.out.print("@");
    }
    for(int l=2;l<=i;l++)
    {
    System.out.print("@");
    }
    System.out.println();
    }
    for(int i=1;i<=3;i++)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print(" ");
    }
    for(int k=3;k>=i;k--)
    {
    System.out.print("@");
    }
    for(int l=2;l>=i;l--)
    {
    System.out.print("@");
    }
    System.out.println();
    }
    }
    }


    -------------------------------------------------


    *
    ***
    *****
    ***
    *

    ReplyDelete
  15. /*
    1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1
    */class NestedLoop2
    {
    public static void main(String[] args) {
    int i=1,j;
    for(i=5;i>=1;i--)
    {
    for(j=1; j<=i;j++)
    {
    System.out.print(j+" ");

    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  16. /*
    A a B b C
    A a B b
    A a B
    A a
    A
    */
    class ABCDE2
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    int asc=65;
    for(int j=1;j<=6-i;j++)
    {
    if(j%2!=0)
    System.out.print((char)asc+" ");
    else
    {
    System.out.print((char)(asc+32)+" ");
    asc++;
    }

    }
    System.out.println();


    }
    }


    }

    ReplyDelete
  17. /*
    1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1*/

    class Pattern
    {

    public static void main(String[] args) {

    int i,j;
    for(i=1;i<=5;i++)
    {
    for(j=1;j<=6-i;j++)
    {
    if(i%2!=0)
    System.out.print(j+" ");
    else
    System.out.print(6-j+" ");


    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  18. // ADITYA BAGHEL

    // WAP to print the following statement?

    // 1 2 3 4 5
    // 1 2 3 4
    // 1 2 3
    // 1 2
    // 1

    class Loop
    {
    static public void main(String ar[])
    {
    for(int i=5;i>=1;i--)
    {
    for(int j=1;j<=i;j++)
    {
    System.out.print(j+" ");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  19. // ADITYA BAGHEL

    // WAP to print the following statement?

    // A a B b C
    // A a B b
    // A a B
    // A a
    // A

    class Loop
    {
    static public void main(String ar[])
    {
    char up='A';
    char down='a';
    for(int i=5;i>=1;i--)
    {
    for(int j=1;j<=i;j++)
    {
    if(j%2==0)
    System.out.print(down+++" ");
    else
    System.out.print(up+++" ");

    }
    up='A';
    down='a';
    System.out.println();
    }
    }
    }

    ReplyDelete
  20. // ADITYA BAGHEL

    // WAP to print the following statement?

    // 1 0 0 1 0
    // 1 0 0 1
    // 1 0 0
    // 1 0
    // 1

    class Loop
    {
    static public void main(String ar[])
    {
    for(int i=5;i>=1;i--)
    {
    for(int j=1;j<=i;j++)
    {
    if(j==2 || j==3 || j==5)
    System.out.print(0+" ");
    else
    System.out.print(1+" ");
    }
    System.out.println();
    }


    }
    }

    ReplyDelete
  21. // ADITYA BAGHEL

    // WAP to print the following statement?

    // A B C D E
    // B C D E
    // C D E
    // D E
    // E

    class Loop
    {
    static public void main(String ar[])
    {
    char up='A';
    char rank='A';

    for(int i=5;i>=1;i--)
    {
    for(int k=5;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=i;j++)
    {
    System.out.print(up++);
    }
    rank++;
    up=rank;
    System.out.println();

    }

    }


    }

    ReplyDelete
  22. /*
    A B C D E
    B C D E
    C D E
    D E
    E
    */



    class Pattern6
    {
    public static void main(String...args)
    {
    for(int i=0;i<5;i++)
    {
    for(int k=0;k<i;k++)
    System.out.print(" ");
    for(int j=i;j<5;j++)
    {
    System.out.print((char)(65+j));
    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  23. /*
    A B C D E
    B C D E
    C D E
    D E
    E
    */



    class Pattern6
    {
    public static void main(String...args)
    {
    for(int i=0;i<5;i++)
    {
    for(int k=0;k<i;k++)
    System.out.print(" ");
    for(int j=i;j<5;j++)
    {
    System.out.print((char)(65+j));
    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  24. // ADITYA BAGHEL

    // WAP to print the following statement?

    // 8
    // 8 8 8
    // 8 8 8 8 8
    // 8 8 8
    // 8
    class Loop
    {
    static public void main(String ar[])
    {
    int x=0;

    for(int i=1;i<=3;i++)
    {
    for(int k=3;k>=i;k--)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=i+x;j++)
    {
    System.out.print("8");
    }
    x++;
    System.out.println();
    }
    x=2;
    for(int i=1;i<=2;i++)
    {
    for(int k=0;k<=i;k++)
    {
    System.out.print(" ");
    }
    for(int j=1;j<=i+x;j++)
    {
    System.out.print("8");
    }
    x--;
    System.out.println();
    x=-1;
    }

    }
    }

    ReplyDelete
  25. A B C D E
    B C D E
    C D E
    D E
    E
    .............................................................

    class Pattern
    {
    public static void main(String args[])
    {
    int i,j,k;
    int l=0;
    for(i=1;i<=5;i++)
    {
    char ch=65;
    for(k=1;k<=i-1;k++)
    {
    System.out.print(" ");
    }
    for(j=i;j<=5;j++)
    {
    System.out.print((char)(ch+l)+"");
    ch++;
    }
    System.out.println();
    l++;
    }
    }
    }

    ReplyDelete
  26. 8
    888
    88888
    888
    8


    class Star{
    public static void main(String args[])
    {
    int i,j,k;
    for(i=1;i<=3;i++)
    {
    for(k=1;k<(5-i-1);k++)
    {
    System.out.print(" ");}
    for(j=1;j<=(2*i-1);j++)
    {System.out.print("8");}
    System.out.println();
    }
    for(i=1;i<=2;i++)
    {
    for(k=1;k<=i;k++)
    {
    System.out.print(" ");}
    for(j=i;j<=(4-i);j++)
    {System.out.print("8");}
    System.out.println();
    }


    }
    }

    ReplyDelete
  27. kinjal singh sirohiFebruary 13, 2021 at 9:50 PM

    //8
    //888
    //88888
    //888
    //8


    class Eight
    {
    public static void main(String args[])
    {
    int i,j,k;
    for(i=1;i<=3;i++)
    {
    for(k=1;k<(5-i-1);k++)
    {
    System.out.print(" ");}
    for(j=1;j<=(2*i-1);j++)
    {System.out.print("8");}
    System.out.println();
    }
    for(i=1;i<=2;i++)
    {
    for(k=1;k<=i;k++)
    {
    System.out.print(" ");}
    for(j=i;j<=(4-i);j++)
    {System.out.print("8");}
    System.out.println();
    }


    }
    }

    ReplyDelete
  28. //WAP to print
    //12345
    //1234
    //123
    //12
    //1
    class Fn1
    {
    public static void main(String args[])
    {
    for(int i=1;i<6;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }

    }
    }

    ReplyDelete
  29. // To print
    //12345
    //5432
    //123
    //54
    //1
    class Fn2
    {
    public static void main(String args[])
    {
    for(int i=1;i<6;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    if(i%2!=0)
    System.out.print(j);
    else
    System.out.print(6-j);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  30. //To print
    //ABCDE
    // BCDE
    // CDE
    // E
    class Fn4
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    int k = 65;
    for(int j=1;j<i;j++)
    System.out.print(" ");
    for(int a=1;a<=6-i;a++)
    {
    char ch=(char)k;
    System.out.print(ch);
    k++;
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  31. //to print
    // 8
    // 888
    // 88888
    // 888
    // 8
    class Fn6
    {
    public static void main(String args[])
    {
    int i,j,k;
    for(i=1;i<=3;i++)
    {
    for(j=3;j>i;j--)
    System.out.print(" ");
    for(k=1;k<=(2*i-1);k++)
    System.out.print(8);
    System.out.println();
    }
    for(i=2;i>=1;i--)
    {
    for(j=3;j>i;j--)
    System.out.print(" ");
    for(k=1;k<=(2*i-1);k++)
    System.out.print(8);
    System.out.println();
    }
    }
    }

    ReplyDelete
  32. /*
    1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1
    */

    class For15
    {
    public static void main(String rgs[])
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    if(i%2==0)

    {
    System.out.print(6-j);
    }
    else
    System.out.print(j);


    }

    System.out.println();


    }


    }



    }

    ReplyDelete
  33. WAP to print the following statement?

    1 2 3 4 5
    1 2 3 4
    1 2 3
    1 2
    1



    class Nested
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    System.out.print(j);
    }
    System.out.println();
    }
    }

    }

    ReplyDelete
  34. A a B b C
    A a B b
    A a B
    A a
    A


    class NestedA2a
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    int ch=65;
    for(int j=1;j<=6-i;j++)
    {
    if (j%2==0)
    { System.out.print((char)(ch+32)+" ");
    ch++;
    }
    else
    {
    System.out.print((char)ch+" ");
    }
    }
    System.out.println();
    }
    }

    }

    ReplyDelete
  35. 1 2 3 4 5
    5 4 3 2
    1 2 3
    5 4
    1

    class NestedExample3
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    if(i%2!=0)
    System.out.print(j+" ");
    else
    System.out.print((6-j)+" ");
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  36. /*1 0 0 1 0
    1 0 0 1
    1 0 0
    1 0
    1*/


    class Nested1001
    {
    public static void main(String args[])
    {
    for(int i=1;i<=5;i++)
    {
    for(int j=1;j<=6-i;j++)
    {
    if(j==1 || j==4)
    System.out.print(1);
    else
    System.out.print(0);
    }
    System.out.println();
    }
    }
    }

    ReplyDelete
  37. /*
    A B C D E
    B C D E
    C D E
    D E
    E
    */

    class NestedE2A
    {
    public static void main(String args[])
    {
    int num=0;
    for(int i=65;i<=69;i++)
    {
    for(int j=i;j<=69;j++)
    {
    System.out.print((char)j);
    }
    System.out.println();
    num++;
    for(int k=1;k<=num;k++)
    {
    System.out.print(" ");
    }
    }
    }
    }

    ReplyDelete

Post a Comment

POST Answer of Questions and ASK to Doubt

Previous Post Next Post