import java.util.Scanner;
public class StarRhombus
{
public static void main(String[] args)
{
int num;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows : ");
num = sc.nextInt();
for (int r = 1; r <= num; r++) {
for (int sp = num - r; sp >= 1; sp--) {
System.out.print(" ");
}
for (int c = 1; c <= (2 * (r - 1)) + 1; c++) {
System.out.print("*");
}
System.out.println();
}
for (int r = 1; r <= num; r++) {
for (int sp = r; sp >= 1; sp--) {
System.out.print(" ");
}
for (int c = 1; c <= (num - r) * 2 - 1; c++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output:
Enter number of rows : 5
*
***
*****
*******
*********
*******
*****
***
*
BUILD SUCCESSFUL (total time: 2 seconds)
public class StarRhombus
{
public static void main(String[] args)
{
int num;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows : ");
num = sc.nextInt();
for (int r = 1; r <= num; r++) {
for (int sp = num - r; sp >= 1; sp--) {
System.out.print(" ");
}
for (int c = 1; c <= (2 * (r - 1)) + 1; c++) {
System.out.print("*");
}
System.out.println();
}
for (int r = 1; r <= num; r++) {
for (int sp = r; sp >= 1; sp--) {
System.out.print(" ");
}
for (int c = 1; c <= (num - r) * 2 - 1; c++) {
System.out.print("*");
}
System.out.println();
}
}
}
Output:
Enter number of rows : 5
*
***
*****
*******
*********
*******
*****
***
*
BUILD SUCCESSFUL (total time: 2 seconds)
Note: Hello friends, If you have any better solution for this programs then please comment below, I will add your comment as a solution for this programs.
Thanks for visiting my blog.
|
No comments:
Post a Comment