Java Program to Print Mirrored Right Triangle Star Pattern

Write a Java Program to print mirrored right triangle star pattern using for loop. This Java mirrored right angled triangle star pattern example uses two for loops nested inside another to display the output.

package ShapePrograms;

import java.util.Scanner;

public class MirroredRightTriangle1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Mirrored Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Mirrored Right Triangle Star Pattern");
		
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 0 ; j < rows - i; j++ ) 
			{
				System.out.print(" ");
			}
			for (int k = 0 ; k < i; k++ ) 
			{
				System.out.print("*");
			}
			System.out.println();
		}
	}
}
Java Program to Print Mirrored Right Triangle Star Pattern 1

In this Java mirrored right triangle star pattern program, we replaced for loops with while loops.

package ShapePrograms;

import java.util.Scanner;

public class MirroredRightTriangle2 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Mirrored Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("-- Printing Mirrored Right Triangle Star Pattern --");
		int j, k, i = 1;
		while(i <= rows ) 
		{
			j = 0 ;
			while( j < rows - i ) 
			{
				System.out.print(" ");
				j++;
			}
			k = 0 ;
			while( k < i) 
			{
				System.out.print("*");
				k++;
			}
			System.out.println();
			i++;
		}
	}
}
Enter Mirrored Right Triangle Pattern Rows = 10
-- Printing Mirrored Right Triangle Star Pattern --
         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********

Java Program to Print Mirrored Right Triangle Star Pattern using do while loop

package ShapePrograms;

import java.util.Scanner;

public class MirroredRightTriangle3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Mirrored Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("-- Printing Mirrored Right Triangle Star Pattern --");
		int j, k, i = 0;
		do
		{
			j = 0 ;
			do
			{
				System.out.print(" ");
			}while(++j < rows - i);
			k = 0 ;
			do 
			{
				System.out.print("*");
			
			}while( k++ < i);
			System.out.println();
		}while(++i < rows );
	}
}
Enter Mirrored Right Triangle Pattern Rows = 13
-- Printing Mirrored Right Triangle Star Pattern --
             *
            **
           ***
          ****
         *****
        ******
       *******
      ********
     *********
    **********
   ***********
  ************
 *************

In this Java example, the MirroredRightTrianglePat function prints the mirrored right triangle pattern of a given symbol.

package ShapePrograms;

import java.util.Scanner;

public class MirroredRightTriangle4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Mirrored Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Character for Mirrored Right Triangle Pattern = ");
		char ch = sc.next().charAt(0);
		
		System.out.println("-- Printing Mirrored Right Triangle Pattern --");
		MirroredRightTrianglePat(rows, ch);
		
	}
	public static void MirroredRightTrianglePat(int rows, char ch) {
		for (int i = 1 ; i <= rows; i++ ) 
		{
			for (int j = 0 ; j < rows - i; j++ ) 
			{
				System.out.print(" ");
			}
			for (int k = 0 ; k < i; k++ ) 
			{
				System.out.print(ch);
			}
			System.out.println();
		}
	}
}
Enter Mirrored Right Triangle Pattern Rows = 17
Character for Mirrored Right Triangle Pattern = #
-- Printing Mirrored Right Triangle Pattern --
                #
               ##
              ###
             ####
            #####
           ######
          #######
         ########
        #########
       ##########
      ###########
     ############
    #############
   ##############
  ###############
 ################
#################

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.