Advertisement
Krassi_Daskalova

NestedLoops_NumberPyramid

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