-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpattern diamond.java
More file actions
32 lines (31 loc) · 984 Bytes
/
pattern diamond.java
File metadata and controls
32 lines (31 loc) · 984 Bytes
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
class sample213{
public static void main(String[] args) {
int n = 5; // maximum number of star present in 1 line
int space=((n-1)/2);
int backspa=n-space;
int num=1;
// upper half
for (int i=0 ; i<((n+1)/2) ;i++){
for (int j=0 ;j<space;j++){
System.out.print(" "); //Add space to the pattern
}
for (int star=0 ;star<num ;star++){
System.out.print("*"); //add * to the pattern
}
space-=1;
num+=2;
System.out.println();
}
//bottom half
for (int k=0;k<((n+1)/2);k++){
num-=2;
for (int spa=0;spa<k;spa++){
System.out.print(" ");
}
for (int sta=0;sta<num ;sta++){
System.out.print("*");
}
System.out.println();
}
}
}