-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode_Diamond_Of_Stars.java
More file actions
64 lines (57 loc) · 1.5 KB
/
Code_Diamond_Of_Stars.java
File metadata and controls
64 lines (57 loc) · 1.5 KB
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
// Problem
// Result
// Code : Diamond of stars
// Send Feedback
// Print the following pattern for the given number of rows.
// Note: N is always odd.
// Pattern for N = 5
// The dots represent spaces.
// Input format :
// N (Total no. of rows and can only be odd)
// Output format :
// Pattern in N lines
// Constraints :
// 1 <= N <= 49
// Sample Input 1:
// 5
// Sample Output 1:
// *
// ***
// *****
// ***
// *
import java.util.Scanner;
public class Code_Diamond_Of_Stars {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int n1 = (n / 2) + 1;
int n2 = (n / 2);
// Upper Part
for (int i1 = 1; i1 <= n1; i1++) {
for (int space1 = 1; space1 <= n1 - i1; space1++) {
System.out.print(" ");
}
for (int star1 = 1; star1 <= 2 * i1 - 1; star1++) {
System.out.print("*");
}
System.out.println();
}
// Down Part
int value1 = 1;
for (int i2 = n2; i2 >= 1; i2--) {
for (int space2 = 1; space2 <= value1; space2++) {
System.out.print(" ");
}
value1++;
for (int star2 = 1; star2 <= i2; star2++) {
System.out.print("*");
}
for (int starRight = 1; starRight <= i2 - 1; starRight++) {
System.out.print("*");
}
System.out.println();
}
s.close();
}
}