Advertisement
andarz

Equal Arrays

Feb 17th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package ArraysLab;
  2.  
  3. import java.util.Arrays;
  4. import java.util.Scanner;
  5.  
  6. public class EqualArrays {
  7.     public static void main(String[] args) {
  8.         Scanner keys = new Scanner(System.in);
  9.  
  10.         int[] arr1 = Arrays.stream(keys.nextLine().split(" "))
  11.                 .mapToInt(Integer::parseInt).toArray();
  12.         int[] arr2 = Arrays.stream(keys.nextLine().split(" "))
  13.                 .mapToInt(Integer::parseInt).toArray();
  14.  
  15.         int sumArr = 0;
  16.  
  17.         for (int i = 0; i < arr1.length; i++) {
  18.             sumArr += arr1[i];
  19.             if (arr1[i] != arr2[i]) {
  20.                 System.out.println(String.format
  21.                         ("Arrays are not identical. Found difference at %d index.", i));
  22.                 return;
  23.  
  24.             }
  25.         }
  26.         System.out.println(String.format
  27.                 ("Arrays are identical. Sum: %d", sumArr));
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement