Advertisement
marking2112

NLNumberPiramid

Oct 23rd, 2018
144
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 Demo {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int number = Integer.parseInt(scanner.nextLine());
  8.         int counter = 0;
  9.  
  10.         for (int i = 1; i <= number; i++) {
  11.             for (int j = 1; j <= i; j++) {
  12.                 counter ++;
  13.                 System.out.printf("%d ", counter);
  14.                 if (counter == number){
  15.                     return;
  16.                 }
  17.             }
  18.             System.out.println();
  19.         }
  20.  
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement