Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class Main
- {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the first array: ");
- String arrayOne = sc.nextLine();
- String[] arrOne = arrayOne.split(" ");
- int[] arr1 = Arrays.stream(arrOne).mapToInt(e -> Integer.parseInt(e)).toArray();
- System.out.print("Enter the second array: ");
- String arrayTwo = sc.nextLine();
- String[] arrTwo = arrayTwo.split(" ");
- int[] arr2 = Arrays.stream(arrTwo).mapToInt(e -> Integer.parseInt(e)).toArray();
- int sum = 0;
- boolean isTrue = true;
- if(arr1.length == arr2.length){
- for(int i = 0;i<arr1.length;i++){
- if(arr1[i] != arr2[i]){
- System.out.println("Arrays are not identical.Found difference at index: " + i);
- isTrue = false;
- break;
- }
- sum += arr1[i];
- }
- }
- if(isTrue == true){
- System.out.println("Arrays are identical.Sum: " + sum);
- }
- }
- }
Add Comment
Please, Sign In to add comment