Advertisement
Ivakis

Number Pyramid

Sep 7th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 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 n = Integer.parseInt(scanner.nextLine());
  8.  
  9. int counter = 1;
  10.  
  11. for (int rows = 1; rows <= n ; rows++) {
  12. for (int cols = 1; cols <= rows ; cols++) {
  13. System.out.print(counter + " ");
  14. counter++;
  15.  
  16. if(counter > n){
  17. return;
  18. }
  19. }
  20. System.out.println();
  21. }
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement