Advertisement
emodev

Untitled

Jan 20th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package f02_Matrices.Lab;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.Arrays;
  7.  
  8. public class P03_IntersectionOfTwoMatrices {
  9. public static void main(String[] args) throws IOException {
  10. BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  11.  
  12. int row = Integer.parseInt(reader.readLine());
  13. int col = Integer.parseInt(reader.readLine());
  14.  
  15. char[][] first = readMatrixFromConsole(reader, row, col);
  16. char[][] second = readMatrixFromConsole(reader, row, col);
  17. char[][] result = new char[row][col];
  18.  
  19. for (int i = 0; i < first.length; i++) {
  20. for (int j = 0; j < first[0].length; j++) {
  21. if (first[i][j] == (second[i][j])) {
  22. result[i][j] = first[i][j];
  23. } else {
  24. result[i][j] = '*';
  25. }
  26. }
  27. }
  28.  
  29. for (int i = 0; i < result.length; i++) {
  30. for (int j = 0; j < result[0].length; j++) {
  31. System.out.print(result[i][j] + " ");
  32. }
  33. System.out.println();
  34. }
  35.  
  36.  
  37. }
  38.  
  39. private static char[][] readMatrixFromConsole(BufferedReader reader, int row, int col) throws IOException {
  40.  
  41. char[][] matrix = new char[row][col];
  42.  
  43. for (int i = 0; i < row; i++) {
  44. String[] array = reader.readLine().split(" ");
  45. for (int j = 0; j < col; j++) {
  46. matrix[i][j] = array[j].charAt(0);
  47. }
  48. }
  49. return matrix;
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement