Previous Article Next Article 5.10 Loop pattern Logic in Java Tutorial
Posted in Java

5.10 Loop pattern Logic in Java Tutorial

5.10 Loop pattern Logic in Java Tutorial Posted on June 8, 201822 Comments



Improve your Programming Skills

Free Java Course

using loop in java to print pattern

22 comments

  1. Sir, this is also executing with below logic, it is almost same.

    public static void main(String[] args) {
    for(int i=1;i<=4;i++){
    for (int j=1;j<=4;j++){

    int k = i+j-1;
    if (k<=4)
    System.out.print(k+" ");
    else System.out.print(k-4+" ");

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

  2. class abc
    {
    public static void main(String a[])
    {
    int i=0,j=0;
    for(i=0;i<4;i++)
    {
          for(j=0;j<4;j++)
                 System.out.print((i+j)%4+1);
         System.out.println();
    }
    }
    }

  3. HW q
    class LoopTest4
    {
    public static void main(String args[])
    {

    int i,j;
    int a=1;
    int b=1;

    for(i=1;i<=4;i++)
    {
    a=i;
    b=1;
    for(j=1;j<=4;j++)
    {

    if(a>4)
    {

    System.out.print(b);
    b++;
    }
    else
    {
    System.out.print(a);
    }
    a++;

    }

    System.out.println();
    }

    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *