Java Program to Print half inverted Pyramid
Hello friends, In this post, we see the simple java code to print the above pattern. To print the pattern we use 2 for loop, first for rows and second for columns.
We initialize two variables i.e. i and j as an integer, i for Row and j for column. The difference between the keyword print and println is, print is use to print the data/statement, as well as the second data/statement is print in front of first line. For example,
Code:
class print_printlnDemo
{
public static void main(String args[])
{
System.out.print("Java ");
System.out.print("Programming ");
System.out.print("Softwere");
}
}
Output:
Println is use to print the data/statement, as well as the second data/statement is print at next line. For example,
Code:
class print_printlnDemo
{
public static void main(String args[])
{
System.out.print("Java ");
System.out.println("Programming ");
System.out.println("Softwere");
}
}
Output:
Java Program to Print half inverted Pyramid
class DisplayPattern
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
Output:
Java Half Pyramid Pattern
Reviewed by Amit Waghmare
on
December 09, 2019
Rating:
No comments: