Advertisement
Spocoman

06. Equal Arrays

Oct 20th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int[] arrOne = Arrays
  9.                 .stream(scanner.nextLine().split(" "))
  10.                 .mapToInt(Integer::parseInt)
  11.                 .toArray();
  12.  
  13.         int[] arrTwo = Arrays
  14.                 .stream(scanner.nextLine().split(" "))
  15.                 .mapToInt(Integer::parseInt)
  16.                 .toArray();
  17.  
  18.         if (Arrays.equals(arrOne, arrTwo)) {
  19.             System.out.printf("Arrays are identical. Sum: %d\n", Arrays.stream(arrOne).sum());
  20.         } else {
  21.             for (int i = 0; i < arrOne.length; i++) {
  22.                 if (arrOne[i] != arrTwo[i]) {
  23.                     System.out.printf("Arrays are not identical. Found difference at %d index.\n", i);
  24.                     break;
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement