Inverted half pyramid with numbers pattern in java.
import java.util.*;
public class invertedhalfpyramidwithnumbers {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the row no.=");
int n=sc.nextInt();
for(int i=1; i<=n; i++){
for(int j=1; j<=n-i+1; j++){
System.out.print(j+" ");
}
System.out.println();
}
}
}
■》Output->
Enter the row no.=5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
-------------------------------------------------------------------
Comments
Post a Comment