Guest User

Untitled

a guest
Jan 1st, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class IntersectionOfTwoMatrices {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. int matrixRow = Integer.parseInt(scanner.nextLine());
  8. int matrixColumn = Integer.parseInt(scanner.nextLine());
  9.  
  10. String[][] firstMatrix = new String[matrixRow][];
  11. String[][] secondMatrix = new String[matrixRow][];
  12.  
  13. for (int i = 0; i < firstMatrix.length; i++) {
  14. String[] arr = scanner.nextLine().split(" ");
  15. firstMatrix[i] = arr;
  16. }
  17.  
  18. for (int i = 0; i < secondMatrix.length; i++) {
  19. String[] arr = scanner.nextLine().split(" ");
  20. secondMatrix[i] = arr;
  21. }
  22.  
  23. for (int i = 0; i < firstMatrix.length; i++) {
  24. for (int j = 0; j < firstMatrix[i].length; j++) {
  25. if (firstMatrix[i][j].equals(secondMatrix[i][j])) {
  26. if (j == matrixColumn - 1) {
  27. System.out.print(firstMatrix[i][j]);
  28. } else {
  29. System.out.print(firstMatrix[i][j] + " ");
  30. }
  31. } else {
  32. if (j == matrixColumn - 1) {
  33. System.out.print("*");
  34. } else {
  35. System.out.print("*" + " ");
  36. }
  37. }
  38. }
  39. System.out.println();
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment