aneliabogeva

PyramidOfNumbers

Dec 13th, 2020
449
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class PyramidOfNumbers {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         Integer n = Integer.parseInt(scanner.nextLine());
  7.         Integer current = 1;
  8.         Boolean isBigger = false;
  9.  
  10.         for(int rows = 1; rows <= n; rows++){
  11.             for(int cols = 1; cols <= rows; cols++){
  12.                 if(current > n){
  13.                     isBigger = true;
  14.                     break;
  15.                 }
  16.                 System.out.print(current + " ");
  17.                 current++;
  18.             }
  19.             if(isBigger){
  20.                 break;
  21.             }
  22.             System.out.println();
  23.         }
  24.  
  25.     }
  26. }
  27.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×