-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamond.java
More file actions
42 lines (36 loc) · 902 Bytes
/
Diamond.java
File metadata and controls
42 lines (36 loc) · 902 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
33
34
35
36
37
38
39
40
41
42
/*
@author Muhammed Fatih ÖZDİL
@since 03/03/2021
*/
package algorithmExamples;
public class Diamond {
public static void main(String[] args) {
int num = 7;
int count=1;
int k= 1;
while(k<=num){
for (int i = 0; i < num-k; i++) {
System.out.print(" ");
}
for (int j = 0; j < count; j++) {
System.out.print("*");
}
k++;
System.out.println();
count+=2;
}
k-=2;
count-=4;
while(k>=1){
for (int i = 0; i < num-k; i++) {
System.out.print(" ");
}
for (int j = count; j > 0 ; j--) {
System.out.print("*");
}
k--;
System.out.println();
count-=2;
}
}
}