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