-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathHalf_Diamond_Pattern.java
48 lines (45 loc) · 1.18 KB
/
Half_Diamond_Pattern.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
/*
Write a program to print N number of rows for Half Diamond pattern using stars and numbers
Note : There are no spaces between the characters in a single line.
*/
import java.util.Scanner;
public class Half_Diamond_Pattern {
public static void main(String[] args) {
// Write your code here
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println("*");
for (int i = 1; i <= n; i++)
{
int j = 1;
System.out.print("*");
while (j <= i)
{
System.out.print(j);
j++;
}
j--;
while (--j >= 1)
{
System.out.print(j );
}
System.out.println("*");
}
for (int i = n - 1; i >= 1; i--)
{
int j = 1;
System.out.print("*");
while (j <= i) {
System.out.print(j);
j++;
}
j--;
while (--j >= 1)
{
System.out.print(j );
}
System.out.println("*");
}
System.out.println("*");
}
}