Pattern Printing 4

3/28/2012 code-examplecsharppattern-printing

# Summary

The following code prints in the form of pyramid as shown below.

   *
  ***
 *****
*******
 *****
  ***
   *
1
2
3
4
5
6
7

# Screenshot

Patter Printing 4 Screenshot

# Code

package com.rohansakhale.quicktest;

/**
 *
 * @author Rohan Sakhale
 */
public class Pattern5 {

    public static void main(String[] args) {
        int i, j, k = 0;
        for (i = 1; i <=4; i++) {
            for (j = 4; j > i; j--) {
                System.out.print(" ");
            }
            for (k = 0; k < (2 * i - 1); k++) {
                System.out.print("*");
            }
            System.out.println(");
        }
        for (i = (k - i + 1); i > 0; i--) {
            for (j = 4; j > i; j--) {
                System.out.print(" ");
            }
            for(k = 0; k < (2 * i - 1);k++){
                System.out.print("*");
            }
            System.out.println(");
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30