Java Program to Print Star Pattern (Right Triangle)

In this tutorials, we will discuss on the Java Program to Print Star Pattern (Right Triangle) which is one of the most commonly asked interview question. Whether you are freshers or an experience, this Java programs is asked quit often to test you basic understanding of loops concepts i.e. for loop and interviewer can check how good you are in the Java concepts.

Steps:

  1. Initial the number of rows
  2. Write two for loops for ‘i’ and ‘j’
  3. In the ‘j’ loop, print the star(*)
  4. And in the ‘i’ loop. print the new line

Java Program:

package TestAutomationCentral;

public class RightTrianglePattern {
    public static void main(String[] args) {
        int rows = 5;
        for(int i=1;i<=rows;i++){
            for(int j =1;j<=i;j++){
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Output:

*
**
***
****
*****
Share

Leave a Reply