Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class IntersectionOfTwoMatrices {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int matrixRow = Integer.parseInt(scanner.nextLine());
- int matrixColumn = Integer.parseInt(scanner.nextLine());
- String[][] firstMatrix = new String[matrixRow][];
- String[][] secondMatrix = new String[matrixRow][];
- for (int i = 0; i < firstMatrix.length; i++) {
- String[] arr = scanner.nextLine().split(" ");
- firstMatrix[i] = arr;
- }
- for (int i = 0; i < secondMatrix.length; i++) {
- String[] arr = scanner.nextLine().split(" ");
- secondMatrix[i] = arr;
- }
- for (int i = 0; i < firstMatrix.length; i++) {
- for (int j = 0; j < firstMatrix[i].length; j++) {
- if (firstMatrix[i][j].equals(secondMatrix[i][j])) {
- if (j == matrixColumn - 1) {
- System.out.print(firstMatrix[i][j]);
- } else {
- System.out.print(firstMatrix[i][j] + " ");
- }
- } else {
- if (j == matrixColumn - 1) {
- System.out.print("*");
- } else {
- System.out.print("*" + " ");
- }
- }
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment