Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TwoDimensionalArrayTest {
- public static boolean equals(int[][] a, int[][] b) {
- for (int i = 0; i < a.length; i++) {
- for (int j = 0; j < a[i].length; j++) {
- if (a[i][j] != b[i][j]) return false;
- }
- }
- return true;
- }
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("How many elements (the size) in the first array ==> ");
- int rows1 = input.nextInt();
- int cols1 = input.nextInt();
- input.nextLine();
- int[][] array1 = new int[rows1][cols1];
- System.out.println("Enter the elements of the first array ==> ");
- for (int i = 0; i < rows1; i++) {
- String[] parts = input.nextLine().trim().split("\\s+");
- for (int j = 0; j < cols1; j++) {
- array1[i][j] = Integer.parseInt(parts[j]);
- }
- }
- System.out.print("How many elements (the size) in the second array ==> ");
- int rows2 = input.nextInt();
- int cols2 = input.nextInt();
- input.nextLine();
- int[][] array2 = new int[rows2][cols2];
- System.out.println("Enter the elements of the second array ==> ");
- for (int i = 0; i < rows2; i++) {
- String[] parts = input.nextLine().trim().split("\\s+");
- for (int j = 0; j < cols2; j++) {
- array2[i][j] = Integer.parseInt(parts[j]);
- }
- }
- if (rows1 != rows2 || cols1 != cols2) {
- System.out.println("The size of the two arrays are not equals");
- } else {
- if (equals(array1, array2)) {
- System.out.println("The two arrays are strictly identical arrays");
- } else {
- System.out.println("The two arrays are not strictly identical arrays");
- }
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment