This can be again be achieved by using nested loops and calculatingly adding spaces and stars as shown in the logic below:
public class InterviewBitLeftPyramid{
public static void printLeftTriangleStars(int n) {
int j;
for(int i=0; i<n; i++){ // outer loop for number of rows(n)
for(j=2*(n-i); j>=0; j--){ // for spaces
System.out.print(" "); // to print space
}
for(j=0; j<=i; j++){ // for columns
System.out.print("* "); // Print star and give space
}
System.out.println(); // Go to next line after every row
}
}
public static void main(String args[]){
printLeftTriangleStars(5); //print stars of 5 rows in left triangle fashion
}
}
Output:
*
* *
* * *
* * * *
* * * * *