Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import org.w3c.dom.ls.LSOutput;
- import java.util.Scanner;
- public class proBen {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String[] firstArray = scan.nextLine().split(" ");
- String[] secondArray = scan.nextLine().split(" ");
- int[] firstInt= new int[firstArray.length];
- int[] secondInt = new int [secondArray.length];
- for (int i = 0; i <firstInt.length ; i++) {
- firstInt[i]=Integer.parseInt(firstArray[i]);
- }
- for (int i = 0; i <secondInt.length ; i++) {
- secondInt[i] = Integer.parseInt(secondArray[i]);
- }
- boolean notEqual = false;
- int sum =0;
- int secondSum=0;
- for (int i = 0; i <firstInt.length ; i++) {
- sum += firstInt[i];
- secondSum +=secondInt[i];
- if (firstInt[i] != secondInt[i]){
- System.out.printf("Arrays are not identical. Found difference at %d index.",i);
- notEqual = true;
- break;
- }
- }
- if (sum == secondSum){
- System.out.printf("Arrays are identical. Sum: %d", sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment