Easy Numbers Pyramid in Java
- Categories Java
Write a java program to print Numbers Pyramid.
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
import java.util.Scanner; public class NumberPyramid { public static void main(String args[]) { int i,j,n; Scanner sc = new Scanner(System.in); System.out.println("Enter the no of lines"); n=sc.nextInt(); for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { System.out.print(" "); } for(j=i;j>0;j--) { System.out.print(" "+j); } for(j=2;j<=i;j++) { System.out.print(" "+j); } System.out.println(); } } }
You may also like
Single Linked List Programs in Java
28 August, 2021
Implementing Stack using Array in Java
28 August, 2021
Constructor Programs
3 July, 2021