Table of Contents
Introduction
In this article, we will explore Java Program to Print Left Triangle Star Pattern. The program in this article prints out the left triangular star pattern as follows:
Example:
Input : n = 5
Output:
* * * * * * * * * * * * * * *
Here the input n to the program from the user or otherwise determines the number of rows of the pattern that will be printed out.
Sample Coe for Left Triangle Star Pattern
import java.io.*; //Java code to demonstrate right star triangle public class Demo { //Function to demonstrate printing pattern public static void starLeft (int n) { int a, b; //outer loop to handle the number of rows //k in this case for (a = 0; a < n; a++) { //inner loop to handle number of columns //values changing according to outer loop for (b = 2 * (n - a); b > = 0; b --) { //printing stars System.out.print (“ ”); } //nested third loop for (b = 0; b < = a; b ++) { //Printing stars System.out.println (“ * “); } //end line System.out.println (); } } //Driver Function public static void main (String args []) { int k = 5; starLeft (k); } }
OUTPUT
* * * * * * * * * * * * * * *
0 Comments