deiom

Untitled

Jun 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class NxNMatrix {
  4. //NxN Matrix
  5. //Write a method that receives a single integer n and prints nxn matrix with that number.
  6. //Examples
  7. //Input Output
  8. //Input:3
  9. //Output:
  10. //3 3 3
  11. //3 3 3
  12. //3 3 3
  13. //Input: 7
  14. //Output:
  15. //7 7 7 7 7 7 7
  16. //7 7 7 7 7 7 7
  17. //7 7 7 7 7 7 7
  18. //7 7 7 7 7 7 7
  19. //7 7 7 7 7 7 7
  20. //7 7 7 7 7 7 7
  21. //7 7 7 7 7 7 7
  22. //Input:2
  23. //Output:
  24. //2 2
  25. //2 2
  26. public static void main(String[] args) {
  27. Scanner scanner = new Scanner(System.in);
  28.  
  29. int n= Integer.parseInt(scanner.nextLine());
  30.  
  31. for (int i=0; i<n;i++){
  32. for(int j=0;j<n;j++){
  33. System.out.print(n+ " ");
  34. }
  35. System.out.println();
  36.  
  37. }
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment