i am working to get the average of the temperature input given by user and this is my code so far but i am getting "Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1" , i don't understand where did i do wrong.
import javax.swing.JOptionPane;
public class JavaApplication1 {
static double [] weekdays= new double[6];
static String[] weekdaysNames = new String[]{"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
public static void promptTemp(){
for(int i=0;i<weekdays.length;i++){
for(int j=6;j<weekdaysNames.length;j--){
weekdays[i] =Double.valueOf(JOptionPane.showInputDialog(null, "Please enter" + weekdaysNames[j] + "temperature?",
"TempApp", JOptionPane.QUESTION_MESSAGE));
}
}
}
public static double calcAverage(double [] value){
double sum=0.0;
for(int i=0;i<value.length;i++){
sum=sum+value[i];
}
double average = sum/(value.length);
return average;
}
public static void main(String[] args) {
promptTemp();
double k=calcAverage(weekdays);
System.out.println(k);
}
}