veronikaaa86

01. Number Pyramid

Mar 14th, 2021 (edited)
453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P01NumberPyramid {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         int currentNum = 0;
  10.         for (int rows = 1; rows <= n; rows++) {
  11.             for (int cols = 1; cols <= rows; cols++) {
  12.                 currentNum++;
  13.  
  14.                 if (currentNum > n){
  15.                     break;
  16.                 }
  17.  
  18.                 System.out.printf("%d ", currentNum);
  19.                 //System.out.print(currentNum + " ");
  20.             }
  21.             if (currentNum > n){
  22.                 break;
  23.             }
  24.             System.out.println();
  25.  
  26.         }
  27.     }
  28. }
  29.  
Add Comment
Please, Sign In to add comment