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