Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class NxNMatrix {
- //NxN Matrix
- //Write a method that receives a single integer n and prints nxn matrix with that number.
- //Examples
- //Input Output
- //Input:3
- //Output:
- //3 3 3
- //3 3 3
- //3 3 3
- //Input: 7
- //Output:
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //7 7 7 7 7 7 7
- //Input:2
- //Output:
- //2 2
- //2 2
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n= Integer.parseInt(scanner.nextLine());
- for (int i=0; i<n;i++){
- for(int j=0;j<n;j++){
- System.out.print(n+ " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment