-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathpattern2:Diamond of stars
52 lines (42 loc) · 1.01 KB
/
pattern2:Diamond of stars
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
import java.util.Scanner;
public class Solution {
public static void diamondOfStars(int n) {
int i=1;
int n1=(n+1)/2;
while(i<=n1)
{
int space=1;
while(space<=n1-i)
{
System.out.print(" ");
space++;
}
int k=1;
while(k<=(2*i-1))
{
System.out.print("*");
k++;
}
i++;
System.out.println();
}
int n2=n/2;
i=n2;
while(i<=n2 && i!=0)
{
int space=1;
while (space<=n2-i+1)
{
System.out.print(" ");
space++;
}
int j=1;
while(j<=(2*i-1)){
System.out.print("*");
j++;
}
i--;
System.out.println();
}
}
}