Please login

Prime

Prepinsta Prime

Video courses for company/skill based Preparation

(Check all courses)
Get Prime Video
Prime

Prepinsta Prime

Purchase mock tests for company/skill building

(Check all mocks)
Get Prime mock

Java Program for Printing Mirrored Rhombus Star Pattern

Printing Mirrored Rhombus Star Pattern

In this problem we’re going to code a Java Program for printing mirrored rhombus star pattern.

For doing so we’ll take a number input from user and store it in variable rows and then run the for loop start from i=0 to ii which print the spaces and then take a another loop to print star start from j=0 to j

Java Program for Mirrored Rhombus Star Pattern

Algorithm:

  1. Take the number of rows as input from the user (length of side of rhombus) and store it in any variable.(‘row‘ in this case).
  2. Run a loop ‘row’ number of times to iterate through each of the rows. From i=0 to i<row. The loop should be structured as for(int i=0;i<rows;i++)
    1.  Run a nested loop inside the main loop to print the spaces before the rhombus. From j=row to j>i. The loop should be structured as for(int j=rows;j>i;j–)
  3. Run another nested loop inside the main loop after the previous loop to print the stars in each column of a row. From j=0 to j<row. The loop should be structured as for(int j=0;j<rows;j++) inside this loop print System.out.println(“*”);
  4. Move to the next line by printing a new line System.out.println();

Code in Java:

import java.util.Scanner;
public class Pattern1 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter No");
		int rows = sc.nextInt();
		
		
		for(int i=0;i<rows;i++)      //loop controlling number of rows
		   {
		      for(int j=rows;j>i;j--) //inner loop for spaces
		          System.out.print(" "); //printing spaces
		      for(int j=0;j<rows;j++) //inner loop for printing the stars in each column of a row
		           System.out.print("*"); //printing stars
		      System.out.println(); // printing a new line after each row
	   }
	}
}
This code is contributed by Shubham Nigam (Prepinsta Placement Cell Student) 

One comment on “Java Program for Printing Mirrored Rhombus Star Pattern”