-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiamond2.java
84 lines (41 loc) · 1.26 KB
/
Diamond2.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import java.util.Scanner;
public class Diamond2{
public static void main(String[]args) {
int numberOfStars=0;
int peakNoOfSpaces=0;
int peakNoOfSpaces2=0;
int noStars2=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter a no.");
numberOfStars=input.nextInt();
do{
System.out.println("Enter a no.");
numberOfStars=input.nextInt();
}while(numberOfStars<1 || numberOfStars>19 || numberOfStars%2==0);
peakNoOfSpaces=numberOfStars-1/2;
int bb=peakNoOfSpaces;
noStars2=numberOfStars;
for (int i=0; i<=numberOfStars; i+=2) {
for (int yy=0; yy<=bb; yy++) {
System.out.printf(" ");
}
for (int kk=0; kk<=i; kk++) {
System.out.printf("*");
}
System.out.println("");
bb=bb-1;
}
for (int i=0; i<=numberOfStars; i+=2) {
peakNoOfSpaces2++;
for (int yy=0; yy<=peakNoOfSpaces2; yy++) {
System.out.printf(" ");
}
for (int kk=0; kk<=noStars2; kk++) { //this is printing the same no. of stars eachtime
//the no u r comparing the counter to has to shrink starting from 5
System.out.printf("*");
}
System.out.println("");
noStars2=noStars2-2;
}
}
}