Skip to content

Commit c844cd6

Browse files
committed
Initial commit
1 parent f0c1a04 commit c844cd6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Pattern-2/Half_Diamond_Pattern.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Write a program to print N number of rows for Half Diamond pattern using stars and numbers
3+
Note : There are no spaces between the characters in a single line.
4+
*/
5+
6+
import java.util.Scanner;
7+
8+
public class Half_Diamond_Pattern {
9+
public static void main(String[] args) {
10+
// Write your code here
11+
Scanner sc = new Scanner(System.in);
12+
int n = sc.nextInt();
13+
System.out.println("*");
14+
for (int i = 1; i <= n; i++)
15+
{
16+
int j = 1;
17+
System.out.print("*");
18+
while (j <= i)
19+
{
20+
System.out.print(j);
21+
j++;
22+
}
23+
j--;
24+
while (--j >= 1)
25+
{
26+
System.out.print(j );
27+
}
28+
System.out.println("*");
29+
}
30+
for (int i = n - 1; i >= 1; i--)
31+
{
32+
int j = 1;
33+
System.out.print("*");
34+
while (j <= i) {
35+
System.out.print(j);
36+
j++;
37+
}
38+
j--;
39+
while (--j >= 1)
40+
{
41+
System.out.print(j );
42+
}
43+
System.out.println("*");
44+
}
45+
System.out.println("*");
46+
47+
}
48+
}

0 commit comments

Comments
 (0)