Advertisement
deyanmalinov

03. Intersection of Two Matrices

May 24th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package DPM;
  2. import java.util.Scanner;
  3. public class Main {
  4.     public static void main(String[] args){
  5.         Scanner scan = new Scanner(System.in);
  6.         int rows = Integer.parseInt(scan.nextLine());
  7.         int cols = Integer.parseInt(scan.nextLine());
  8.         char[][] fMatrix = new char[rows][cols];
  9.         char[][] sMatrix = new char[rows][cols];
  10.  
  11.         for (int row = 0; row < fMatrix.length; row++) {
  12.             String [] line = scan.nextLine().split(" ");
  13.             for (int col = 0; col < fMatrix[0].length; col++) {
  14.                 fMatrix[row][col] = line[col].charAt(0);
  15.             }
  16.         }
  17.         for (int row = 0; row < sMatrix.length; row++) {
  18.             String [] line = scan.nextLine().split(" ");
  19.             for (int col = 0; col < sMatrix[0].length; col++) {
  20.                 sMatrix[row][col] = line[col].charAt(0);
  21.             }
  22.         }
  23.         for (int row = 0; row < fMatrix.length; row++) {
  24.             System.out.println();
  25.             for (int col = 0; col < fMatrix[0].length; col++) {
  26.                 if (fMatrix[row][col] != sMatrix[row][col]){
  27.                     System.out.print("* ");
  28.                 }else {
  29.                     System.out.print(fMatrix[row][col]+ " ");
  30.                 }
  31.  
  32.             }
  33.  
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement