Skip to content

Commit

Permalink
Merge pull request tarunsinghofficial#544 from msRob0t/main
Browse files Browse the repository at this point in the history
added star diamond.java
  • Loading branch information
tarunsinghofficial authored Oct 20, 2020
2 parents 6e63c4d + 99e3bbb commit 13c621c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Java_Programs_for_beginners/star diamond.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import java.util.Scanner;
public class DiamondPattern
{
public static void main(String args[])
{
int row, i, j, space = 1;
System.out.print("Enter the number of rows you want to print: ");
Scanner sc = new Scanner(System.in);
row = sc.nextInt();
space = row - 1;
for (j = 1; j<= row; j++)
{
for (i = 1; i<= space; i++)
{
System.out.print(" ");
}
space--;
for (i = 1; i <= 2 * j - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
space = 1;
for (j = 1; j<= row - 1; j++)
{
for (i = 1; i<= space; i++)
{
System.out.print(" ");
}
space++;
for (i = 1; i<= 2 * (row - j) - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

0 comments on commit 13c621c

Please sign in to comment.