Skip to content

Commit 74e2b76

Browse files
authored
Merge pull request #101 from Anuragjain20/arj
added diamond pattern program
2 parents bab03be + ef5cc63 commit 74e2b76

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Diamond_Pattern.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.util.Scanner;
2+
public class Diamond
3+
{
4+
public static void main(String args[])
5+
{
6+
int n, i, j, space = 1;
7+
System.out.print("Enter the number of rows: ");
8+
Scanner s = new Scanner(System.in);
9+
n = s.nextInt();
10+
space = n - 1;
11+
for (j = 1; j <= n; j++)
12+
{
13+
for (i = 1; i <= space; i++)
14+
{
15+
System.out.print(" ");
16+
}
17+
space--;
18+
for (i = 1; i <= 2 * j - 1; i++)
19+
{
20+
System.out.print("*");
21+
}
22+
System.out.println("");
23+
}
24+
space = 1;
25+
for (j = 1; j <= n - 1; j++)
26+
{
27+
for (i = 1; i <= space; i++)
28+
{
29+
System.out.print(" ");
30+
}
31+
space++;
32+
for (i = 1; i <= 2 * (n - j) - 1; i++)
33+
{
34+
System.out.print("*");
35+
}
36+
System.out.println("");
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)