SHARE
TWEET

Untitled

a guest Jun 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Pyramid {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.         int 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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top