Nested Loop – Logical Pattern

We already see nested loop in our last blog, now we will work on logical pattern example.

*

12

***

1234

*****

 

Program on – Logical nested loop

class LoopEx5

{

            void method1()

            {

                        int i,j;

                        for(i=1;i<=5;i++)    // Loop

                        {

                                    for(j=1;j<=i;j++)

                                    {

                                                if(i%2==0)

                                                System.out.print(j);

                                                else

System.out.print(“*”);

                                    }

                                    System.out.println();

}

}

}

class loop5

{

          public static void main(String args[])

          {

                   LoopEx5 obj = new LoopEx5();

                    obj.method1();

}

}

Output:

*

12

***

1234

*****

 

You can see nested loops program on YouTube

 

 

If you have problem on this blog, you can directly comment on it. This tutorial will help you understand the concepts of java loop programs.

518total visits,3visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.