Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package f02_Matrices.Lab;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.Arrays;
- public class P03_IntersectionOfTwoMatrices {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int row = Integer.parseInt(reader.readLine());
- int col = Integer.parseInt(reader.readLine());
- char[][] first = readMatrixFromConsole(reader, row, col);
- char[][] second = readMatrixFromConsole(reader, row, col);
- char[][] result = new char[row][col];
- for (int i = 0; i < first.length; i++) {
- for (int j = 0; j < first[0].length; j++) {
- if (first[i][j] == (second[i][j])) {
- result[i][j] = first[i][j];
- } else {
- result[i][j] = '*';
- }
- }
- }
- for (int i = 0; i < result.length; i++) {
- for (int j = 0; j < result[0].length; j++) {
- System.out.print(result[i][j] + " ");
- }
- System.out.println();
- }
- }
- private static char[][] readMatrixFromConsole(BufferedReader reader, int row, int col) throws IOException {
- char[][] matrix = new char[row][col];
- for (int i = 0; i < row; i++) {
- String[] array = reader.readLine().split(" ");
- for (int j = 0; j < col; j++) {
- matrix[i][j] = array[j].charAt(0);
- }
- }
- return matrix;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement