MagdalenaTakeva

MatrixOfNumbers_2

Feb 15th, 2022
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. package Homework_Loops;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PO9_MatrixOfNumbers_2 {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. System.out.println("Enter n: (1 ≤ n ≤ 20) ");
  9. int n = Integer.parseInt(scanner.nextLine());
  10.  
  11. //The outer loop must run from 1 to N,
  12. // the inner loop – from the value of the outer loop to the value of the outer loop + N - 1.
  13.  
  14.  
  15. for (int i = 1; i <= n; i++)
  16. {
  17. for (int j = i; j <= i+n-1; j++)
  18. {
  19. System.out.print(j + " ");
  20. }
  21. System.out.println();
  22. }
  23. }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment