Write a program to display numbers in ascending pyramid pattern java
package com.vel.nestedforloop; import java.util.Scanner; public class ForLoop3 { public static void main(String[] args) { System.out.println("Enter the limit:-"); Scanner sc=new Scanner(System.in); int limit=sc.nextInt(); int k=1; for(int i=1;i<=limit+1;i++) { for(int j=1;j<=i;j++) { System.out.print( k++ +" "); } System.out.println(); } } }
Output: Enter the limit:- 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14
No comments:
Post a Comment