OneCompiler

Printing inverted half pyramid loops concept FAROOQ

159

import java.util.;
public class javaDay_3{
public static void inverted_halfPyramid(int n){
for(int i=1; i<=n; i++)
{
System.out.println(""); //takes to next line when exit from inner loop
for(int j=1; j<=n-i; j++) //for empty spaces
{
System.out.print(" ");
}
for(int j=1; j<=i; j++) //for stars
{
System.out.print("
");
}
}
}
public static void main(String args[]){
Scanner sf=new Scanner(System.in);
System.out.println("Enter number of rows to get pyramid");
int rows=sf.nextInt();
inverted_halfPyramid(rows);
}
}