-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diamond.java
58 lines (49 loc) · 1.21 KB
/
Diamond.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by root on 9/7/17.
*/
public class Diamond {
public static void main(String args[])
{
int n = getN();
upperHalf(n);
//lower half
lowerHalf(n);
}
private static int getN() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n= 0;
try {
n = Integer.parseInt(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return n;
}
private static void upperHalf(int n) {
for(int i=0;i<n;i++)
{
for(int j=0;j<=n-i-1;j++)
System.out.print(" ");
for(int j=0;j<=(2*i);j++)
{
System.out.print("*");
}
System.out.println();
}
}
private static void lowerHalf(int n) {
for(int i=0;i<n-1;i++)
{
for(int j=0;j<=i+1;j++)
System.out.print(" ");
for(int j=0;j<=(2*(n-i-2));j++)
{
System.out.print("*");
}
System.out.println();
}
}
}