题解 | #矩阵相等判定#
矩阵相等判定
https://www.nowcoder.com/practice/2f058b1e89ae43f7ab650c0fd0b71fa8
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int [][]arr1 = new int[n][m]; int [][]arr2 = new int[n][m]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr1[i][j] = sc.nextInt(); } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { arr2[i][j] = sc.nextInt(); } } boolean flag = true; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (!(arr1[i][j] == arr2[i][j])) { flag = false; break; } else { flag = true; } } } if (flag) { System.out.println("Yes"); } else { System.out.println("No"); } } }