diamond in java

Solutions on MaxInterview for diamond in java by the best coders in the world

showing results for - "diamond in java"
Carla
03 Jan 2017
1public class DiamondPattren {
2    public static void diamond() {
3
4        for (int i = 1; i <= 5; i++) {
5            for (int j = 1; j <= 5; j++) {
6                if (j >= (5 - i + 1)) System.out.print("* ");
7                else System.out.print("  ");
8            }
9            for (int j1 = 1; j1 <= 5; j1++) {
10                if (j1 < i) System.out.print("* ");
11                else System.out.print("  ");
12            }
13            System.out.println("");
14        }
15
16        for (int i1 = 1; i1 <= 4; i1++) {
17            for (int j = 0; j <= 4; j++) {
18                if (j <= (i1 - 1)) System.out.print("  ");
19                else System.out.print("* ");
20            }
21            for (int j1 = 1; j1 <= 4; j1++) {
22                if (j1 <= 4-i1) System.out.print("* ");
23                else System.out.print("  ");
24            }
25            System.out.println("");
26        }
27
28
29    }
30}
31