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