Right Angle Triangle Pattern

Right angle triangle is a popular pattern, which is generally asked during interview rounds in companies. So everyone must understand its logic.

public class Tech4Humans {

	public static void main(String[] args) {

		// length of triangle
		int size = 5;

		for (int i = 0; i < size; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print("* ");
			}
			System.out.println();
		}

	}

}

Output

* 
* * 
* * * 
* * * * 
* * * * * 

How to debug Code

Let us understand how to debug the above pattern :

If you are trying to understand a tricky loop then always use pen and paper. By this you will develop the ability to understand the code mentally after some time.

Leave a Comment