Skip to main content
Browse topics

Inverted Left Triangle Example in Java

2 min read Updated May 29, 2026
Share

Introduction

Inverted Left Triangle is a classic Java console program that demonstrates the concept with complete source code and sample output. Pattern programs print shapes with nested loops — common in exams and interviews.

This tutorial walks through the program line by line, explains how the logic works, and highlights best practices you can apply in your own code.

Inverted Left Triangle Example Program

java
class InvertedLeftTriangle {
	public static void main(String[] args) {
		for(int i=5; i>0 ;i--){
			for(int j=0; j < i; j++){
				System.out.print("*");
			}
			System.out.println("");
		}
	}
}

Sample Output

plaintext
*****
****
***
**
*

When to use

Use pattern logic when practicing nested loops or preparing for coding tests that ask for triangle or pyramid output.

How it works

  1. Execution begins in the main method — the JVM calls this method when you run the class.

  2. A loop repeats the block until its condition becomes false.

  3. A loop repeats the block until its condition becomes false.

  4. A println / print call writes text to the console — part of the sample output below.

  5. A println / print call writes text to the console — part of the sample output below.

  6. Compare your console output with the sample output for Inverted Left Triangle to confirm the program behaves correctly.

Best Practices

Common Mistakes

Frequently Asked Questions

What does the Inverted Left Triangle program demonstrate?
It shows how to implement inverted left triangle in Java with a complete runnable example and expected console output.
How do I run this Java program?
Save the code in a `.java` file matching the public class name, compile with `javac`, then run with `java ClassName`.
When would I use this pattern?
Use pattern logic when practicing nested loops or preparing for coding tests that ask for triangle or pyramid output.

Related tutorials

Search tutorials