Question: Can someone please review my source code against the
requirement? It partly works, but then the o...

Can someone please review my source code against the
requirement? It partly works, but then the other times I get [
Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 4 ] or [ Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: 23 ]. Below
is the assignment requirement. Thanks.

Exercise #2: Design and implement a program
(name it CompareArrays) that compares the content of 2
single-dimensional arrays of the same size. The program prompts the
users to enter the array size. Then prompts the user to initialize
each array with integer values. The program defines method
Compare() that takes two signal-dimensional arrays of type integer.
The method compares the content of the arrays and returns true
(Boolean type) if the arrays store same values in the same order.
Otherwise, it returns false. The program main method calls method
Compare()and prints the result from the method as shown below.

import java.util.* ;

public class CompareArrays {

public static void main(String[] args) {

Scanner input = new
Scanner(System.in);

System.out.print("Enter array size:
");
int size = input.nextInt();

int [] array1 = new int
[size];
int [] array2 = new int
[size];

System.out.println("Enter integer(s)
for first array: ");

for (int i = 0; i < size; i++)
{
array1[i] =
input.nextInt();

} // ENDFOR

System.out.println("Enter integer(s)
for second array: ");

for (int j = 0; j < size; j++)
{
array2[j] =
input.nextInt();

} // ENDFOR

if (Compare(array1, array2) == true)
{
System.out.println("Judgement: The arrays are identical");
}
else
System.out.println("Judgement: The arrays are NOT
identical");