What's wrong with my code? Can somebody help? Thanks!
import java.io.*;
public class Array {
public static void main (String[]args) throws IOException {
BufferedReader myinput=new BufferedReader(new InputStreamReader(System.in));
int Arr1[]=new int[5];
int Arr2[]=new int[5];
int SumArr1=0;
int SumArr2=0;
int x=0;
int y=0;
for (x=0;x<Arr1.length;x++) {
System.out.print("Enter Array1: ");
Arr1[x]=Integer.parseInt(myinput.readLine());
SumArr1=Arr1[x]+SumArr1;
}
System.out.println();
for (y=0;y<Arr2.length;y++) {
System.out.print("Enter Array2: ");
Arr2[y]=Integer.parseInt(myinput.readLine());
SumArr2=Arr2[y]+SumArr2;
}
if (SumArr1==SumArr2) {
System.out.println("The arrays are equal.");
}
else {
System.out.println("The arrays are not equal.");
}
if (Arr1[x]==Arr2[y]) {
System.out.println("The arrays are the same.");
}
else {
System.out.println("The arrays are not the same.");
}
}}
When I have finished input numbers it says:
Enter Array1: 5
Enter Array1: 5
Enter Array1: 5
Enter Array1: 5
Enter Array1: 5
Enter Array2: 5
Enter Array2: 5
Enter Array2: 5
Enter Array2: 5
Enter Array2: 5
The arrays are equal.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Array.main(Array.java:36)
C:\Java\bin>