1.

Write a Java Program to display the left triangle star pattern on the system console.

Answer»

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:

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


Discussion

No Comment Found