martinvalchev

Number Pyramid

Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NumberPyramid {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int row = 0;
  8.         int caunt = 0;
  9.  
  10.         while (true) {
  11.             row++;
  12.             for (int i = 1; i <= row; i++) {
  13.                 caunt++;
  14.                 System.out.print(caunt + " ");
  15.                 if (caunt == n) {
  16.                     return;
  17.                 }
  18.             }
  19.             System.out.println();
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment