galinyotsev123

ProgBasicsJavaBook7.1ComplexLoop15numberPyramid

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