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:
- Initial the number of rows
- Write two for loops for ‘i’ and ‘j’
- In the ‘j’ loop, print the star(*)
- 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:
*
**
***
****
*****