public class Array {
public static void main ( String[] args ) {
int DAYS_SIZE = 5;
double[] sales = new double[DAYS_SIZE];
String input;
char userResponse;
Scanner keyboard = new Scanner(System.in);
double total = 0;
double average = 0;
int index = 0;
do {
index++;
System.out.print("Enter sales for day " + index + ": ");
sales[index] = keyboard.nextInt();
System.out.print("Another ( y or n )? " );
input = keyboard.next();
userResponse = input.charAt(0);
} while ( userResponse == 'Y' || userResponse == 'y');
}
}
I keep getting java.lang.ArrayIndexOutOfBoundsException: 5 at the last day
I know why this is happening but i dont know how to solve it