Java Left Triangle Pattern Program Using 'for loop'
Java Left Triangle Pattern Program- more-programs
Using for loop
Left triangle pattern program
class Pattern
{
public static void main(String args[])
{
//i for rows and j for columns
//row denotes the number of rows you want to print
int i, j, row = 20;
//Outer loop work for rows
for (i=0; i<row; i++)
{
//inner loop work for space
for (j=2*(row-i); j>=0; j--)
for (j=2*(row-i); j>=0; j--)
{
//prints space between two stars
System.out.print(" ");
}
//inner loop for columns
for (j=0; j<=i; j++ )
{
//prints star
System.out.print("* ");
}
//throws the cursor in a new line after printing each line
System.out.println();
}
}
}
Java Helloworld program
class Hello1
{
public static void main(String arg[])
{
System.out.println();
System.out.println("Hello World");
}
}
Notepad CMD output
Observe the program and its output carefully
Comments
Post a Comment