Hi I'm just beginning to learn and work with arrays and I was going to try a program that ask the user to enter 8 hourly temperatures and let the program output these temperatures.
When I run the program and enter the 8 temperatures this is what my prompt says:
'Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8 at TemperatureArray.main(TemperatureArray.java:18)'
I have never seen this before.. my code compiles fine but here it is also:
import java.util.*; public class TemperatureArray { static Scanner console = new Scanner(System.in); public static void main(String[] args) { int[] temp = new int[8]; int avg; int index; System.out.println("Enter 8 numbers: "); for (index = 0; index < temp.length; index++) temp[index] = console.nextInt(); System.out.print(temp[index] + " "); } }