TheBulgarianWolf

Number Pyramid

Mar 13th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Main {
  3.   public static void main(String[] args) {
  4.     Scanner sc = new Scanner(System.in);
  5.     Integer n = Integer.parseInt(sc.nextLine());
  6.     int num = 1;
  7.     for(int row = 1; row <= n;row++){
  8.       for(int col = 1; col<= row;col++){
  9.        
  10.         System.out.print(num + " ");
  11.         num++;
  12.         if(num > n){
  13.           break;
  14.         }
  15.        
  16.        
  17.        
  18.       }
  19.       System.out.println();
  20.        if(num > n){
  21.           break;
  22.         }
  23.     }
  24.    
  25.   }
  26. }
Add Comment
Please, Sign In to add comment