I'm just starting a unit in Arrays and I was given some example code to look off of for this very basic introductory program for Arrays. Essentially all I have to do is make two arrays that ask for the temperature for that day of the week. After collecting the info it will simply spit it back out in a string like this.
The temperature on Monday was 16 degrees
The temperature on Tuesday was 18 degrees
... etc.
From what I understood from the example code I received I am doing everything correctly. But when try to run the program (in Netbeans) I get this error.
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at temperatures.Temperatures.main(Temperatures.java:27) Java Result: 1"
Here is the code:
public static void main(String[] args)throws IOException {
// TODO code application logic here
BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
String temp[]= new String[7];
String day[]= new String[7];
day[1]=("Monday");
day[2]=("Tuesday");
day[3]=("Wednesday");
day[4]=("Thursday");
day[5]=("Friday");
day[6]=("Saturday");
day[7]=("Sunday");
for (int i=0; i <7; i++){
System.out.println("Please enter the temperature for" + day[i]);
temp[i]=br.readLine();
}
for (int i=0; i <7; i++){
System.out.println("The high temperature on " + day[i]+ " was "+ temp[i]);
}
}
}