Задача 06.Equal Arrays - от Fundamentals module
Здравейте,
немога да разбера, каде ми е грешката в тази задача, уж открих логиката но ми дава 80 точки.
Може ли малко повече разяснение по нея. Благодаря Ви.
package com.company;
import java.lang.reflect.Array;
import java.util.Scanner;
public class EqualArrays {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String[] firstArray = scan.nextLine().split(" ");
int[] numberFirst = new int[firstArray.length];
String[] secondArray = scan.nextLine().split(" ");
int[] numberSecond = new int[secondArray.length];
int sumFirst = 0;
int diffrent = 0;
int position = 0;
for (int i = 0; i < firstArray.length; i++) {
numberFirst[i] = Integer.parseInt(firstArray[i]);
numberSecond[i] = Integer.parseInt(secondArray[i]);
if (numberFirst[i] != numberSecond[i]){
diffrent++;
position = numberFirst[i] -diffrent;
}
sumFirst += numberFirst[i];
}
if (diffrent == 0){
System.out.printf("Arrays are identical. Sum: %d",sumFirst);
}else {
System.out.printf("Arrays are not identical. Found difference at %d index.",position);
}
}
}
Read two arrays and print on the console whether they are identical or not.
Arrays are identical if their elements are equal.
If the arrays are identical find the sum of the first one and print on the console following message:
"Arrays are identical. Sum: {sum}", otherwise find the first index where the arrays differ and print on the console following message: "Arrays are not identical. Found difference at {index} index."