I can't figure out what the error means that I keep getting on my loop. I have it set to only take 5 arguments, which is my limit, but I can't tell what it's saying:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Duplicates.EnterNumbers(Duplicates.java:20)
at Duplicates.main(Duplicates.java:28)
Here's my code:
import java.util.*;
public class Duplicates
{
Scanner input = new Scanner( System.in );
int i;
int numbers[] = new int[4];
public void EnterNumbers()
{
System.out.println("Please Enter 5 variables: ");
for (i=0; i<=4; i++)
{
System.out.printf("Please enter value in slot " + i + ":");
numbers[i] = input.nextInt();
}
}
public static void main(String[] args)
{
Duplicates DuplicateTest = new Duplicates();
DuplicateTest.EnterNumbers();
}
}