Advertisement
deyanivanov966

NESTED LOOPS - EXERCISE 01. Number Pyramid

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