DEV Community

Guna Sekaran
Guna Sekaran

Posted on

Nested while loop in java

package ifelse;

public class Task1 {
     public static void main(String[] args) {

      int row = 5;
      int colum = 5;
      int a = 0;
   while (a < row) {
    int b = 0;
    while (b < colum) {
      if ((a + b) % 2 == 0) {
         System.out.print("1 ");
    }
    else 
    {
         System.out.print("0 ");
            }
     b++;

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

                 }
             }




    }

   OUTPUT:
        1 0 1 0 1 
        0 1 0 1 0 
        1 0 1 0 1 
        0 1 0 1 0 
        1 0 1 0 1 

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
payilagam_135383b867ea296 profile image
Payilagam

good try