Java Program to Print Hollow Inverted Right Triangle Star Pattern

Write a Java Program to print the hollow inverted right angled triangle star pattern using for loop. This Java hollow inverted right triangle star example uses if statements to check for borders. If it is true, it prints the star; otherwise, it prints an empty space to get the hollow inverted right angled triangle.

package ShapePrograms;

import java.util.Scanner;

public class HollowInvertedRightTriangle1 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Inverted Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Print Hollow Inverted Right Triangle Star Pattern");
		
		for (int i = rows; i > 0; i-- ) 
		{
			if(i == 1 || i == rows) {
				for (int j = 1 ; j <= i; j++ ) 
				{
					System.out.print("*");
				}
			}
			else {
				for (int k = 1 ; k <= i; k++ ) {
					if(k == 1 || k == i) {
						System.out.print("*");
					}
					else {
						System.out.print(" ");
					}
				}
			}
			System.out.println();
		}
	}
}
Enter Hollow Inverted Right Triangle Pattern Rows = 6
Print Hollow Inverted Right Triangle Star Pattern
******
*   *
*  *
* *
**
*

We simplified the above Java hollow inverted right triangle pattern code and removed the extra if else.

package ShapePrograms;

import java.util.Scanner;

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

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

package ShapePrograms;

import java.util.Scanner;

public class HollowInvertedRightTriangle3 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Inverted Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Print Hollow Inverted Right Triangle Star Pattern");
		int j, i = rows;
		
		while( i > 0) 
		{
			j = 1 ;
			while( j <= i) 
			{
				if(j == 1 || j == i || i == 1 || i == rows) 
				{
					System.out.print("*");
				}
				else {
					System.out.print(" ");
				}
				j++;
			}
			System.out.println();
			i-- ;
		}
	}
}
Enter Hollow Inverted Right Triangle Pattern Rows = 11
Print Hollow Inverted Right Triangle Star Pattern
***********
*        *
*       *
*      *
*     *
*    *
*   *
*  *
* *
**
*

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

package ShapePrograms;

import java.util.Scanner;

public class HollowInvertedRightTriangle4 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Inverted Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Print Hollow Inverted Right Triangle Star Pattern");
		int j, i = rows;
		
		do
		{
			j = 1 ;
			do
			{
				if(j == 1 || j == i || i == 1 || i == rows) 
				{
					System.out.print("*");
				}
				else {
					System.out.print(" ");
				}
			} while( ++j <= i) ;
			System.out.println();
		} while( --i > 0);
	}
}
Enter Hollow Inverted Right Triangle Pattern Rows = 14
Print Hollow Inverted Right Triangle Star Pattern
**************
*           *
*          *
*         *
*        *
*       *
*      *
*     *
*    *
*   *
*  *
* *
**
*

In this Java example, the HollowInvertedRightTrianglePat function prints a given symbol’s hollow inverted right angled triangle pattern.

package ShapePrograms;

import java.util.Scanner;

public class HollowInvertedRightTriangle5 {
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Hollow Inverted Right Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.print("Enter Character for Hollow Inverted Right Triangle Pattern = ");
		char ch = sc.next().charAt(0);
		
		System.out.println("Print Hollow Inverted Right Triangle Pattern");
		HollowInvertedRightTrianglePat(rows, ch);		
	}
	
	public static void HollowInvertedRightTrianglePat(int rows, char ch) {
		for (int i = rows; i > 0; i-- ) 
		{
			for (int j = 1 ; j <= i; j++ ) 
			{
				if(j == 1 || j == i || i == 1 || i == rows) 
				{
					System.out.print(ch);
				}
				else {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}
Enter Hollow Inverted Right Triangle Pattern Rows = 16
Enter Character for Hollow Inverted Right Triangle Pattern = #
Print Hollow Inverted Right Triangle Pattern
################
#             #
#            #
#           #
#          #
#         #
#        #
#       #
#      #
#     #
#    #
#   #
#  #
# #
##
#