-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiamond_pattern.txt
More file actions
94 lines (76 loc) · 1.9 KB
/
Copy pathDiamond_pattern.txt
File metadata and controls
94 lines (76 loc) · 1.9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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:
*
***
*****
***
*
Sample Input 2:
3
Sample Output 2:
*
***
*
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
// Write your code here
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int i =1;
int a = n/2 + 1;
int b = n - a;
while(i<=a){
int j = 1;
int x = 1;
int y = 2*i - 2;
while(j<=a+i-1){
if(j<=a-i){
System.out.print(" ");
}else if(j>a-i && j<=a){
System.out.print("*");
x = x+1;
}else if(j>a && j<=a+i-1){
System.out.print("*");
y = y-1;
}
j = j+1;
}
System.out.println();
i = i+1;
}
i = b;
while(i>=1){
int j = 1;
int x = 1;
int y = 2*i - 2;
while(j<=a+i-1){
if(j<=a-i){
System.out.print(" ");
}else if(j>a-i && j<=a){
System.out.print("*");
x = x+1;
}else if(j>a && j<=a+i-1){
System.out.print("*");
y = y-1;
}
j = j+1;
}
System.out.println();
i = i-1;
}
}
}