pattern_14.java
1 /* 2 * Write code to print the following pattern 3 * 1 1 1 1 1 4 * 0 0 0 0 0 5 * 1 1 1 1 1 6 * 0 0 0 0 0 7 * 1 1 1 1 1 8 */ 9 10 public class pattern_14 { 11 public static void main(String[] args) { 12 int rows = 5; 13 int cols = 5; 14 int num; 15 16 for(int i = 0; i <= rows - 1; i++) { 17 if (i % 2 == 0) { 18 num = 1; 19 } else { 20 num = 0; 21 } 22 23 for(int j = 0; j <= cols - 1; j++) { 24 System.out.print(num + " "); 25 } 26 System.out.println(); 27 } 28 } 29 }