Diamond Pattern Program
- Categories Java
Write a Star Diamond pattern Java program as shown, where number of rows is given by user.
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
import java.util.Scanner;
public class StarPyramid { public static void main(String args[]) { Scanner scan = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
int n = scan.nextInt();
for (int i = 1; i<n ; i++) {
for (int j = i; j<=n; j++) {
System.out.print(” “); // decreasing
}
for (int j = 1; j< i; j++) { // increasing
System.out.print(“* “);
}
for (int j = 1; j<=i; j++) { // increasing
System.out.print(“* “);
}
System.out.println();
}
for (int i = 1; i<=n ; i++) {
for (int j = 1; j<=i; j++) { // increasing
System.out.print(” “);
}
for (int j = i; j< n; j++) { // decreasing
System.out.print(“* “);
}
for (int j = i; j<=n; j++) { // decreasing
System.out.print(“* “);
}
System.out.println();
} } }
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021