/ Patterns / pattern_3.java
pattern_3.java
 1  /*
 2   * Write code to print the following patttern 
 3   *             *
 4   *           * * *
 5   *         * * * * *
 6   *       * * * * * * *
 7   *     * * * * * * * * *  
 8   */ 
 9  
10  public class pattern_3 {
11      public static void main(String[] args) {
12          int n = 5; // Number of rows
13  
14          for (int i = 1; i <= n; i++) {
15              // Print spaces
16              for (int j = 1; j <= (n - i); j++) {
17                  System.out.print("  "); // Two spaces for alignment
18              }
19  
20              // Print stars
21              for (int j = 1; j <= (2 * i - 1); j++) {
22                  System.out.print("* ");
23              }
24  
25              System.out.println(); // Move to the next line
26          }
27      }
28  }