-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diamond.java
40 lines (40 loc) · 1.16 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
import java.util.*;
class Diamond{
public static void main(String args[]){
Scanner sc= new Scanner(System.in);
System.out.println("Enter the number: ");
int n=sc.nextInt();
for(int j=1;j<=(2*n)-1;j++){
if(j<=n){
for(int k=1;k<=(n-j);k++){
System.out.print(" ");
}
for(int k=1;k<=(2*j)-1;k++){
if(k%2!=0)
System.out.print("*");
else
System.out.print(" ");
}
for(int k=1;k<=(n-j);k++){
System.out.print(" ");
}
}
else
{
for(int k=j-n;k>0;k--){
System.out.print(" ");
}
for(int k=(4*n-2*j-1);k>0;k--){
if(k%2!=0)
System.out.print("*");
else
System.out.print(" ");
}
for(int k=j-n;k>0;k--){
System.out.print(" ");
}
}
System.out.println();
}
}
}