Advertisement
Guest User

Untitled

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