I am a beginner programmer working on this exercise for an online class. I'm supposed to write a program that takes ten numbers from a user, finds the lowest number, and prints it back. I've viewed a few other similar questions, but couldn't find anything that worked for me. Here's what I have thus far, no errors or anything. I can't figure out why it gives me this:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Exercise6_9.min(Exercise6_9.java:41)
at Exercise6_9.main(Exercise6_9.java:31)
after entering 10 numbers. As a note, I have looked at this question, they are not the same. I wasn't quite asking what my error was and how to solve it, but rather why it's coming up in my example when my IDE shows no problems prior to running the program.
import java.util.Scanner;
public class Exercise6_9 {
public static void main(String[] args) {
double[] numbers = new double[10];
Scanner input = new Scanner(System.in);
System.out.println("Enter 10 numbers.");
for (int i = 0; i < numbers.length; i++ ){
numbers[i] = input.nextDouble();
}
min(numbers);
}
public static double min(double[] numbers){
double min = numbers[10];
for (int i=0;i<numbers.length;i++){
if (numbers[i] < min){
min = numbers[i];
System.out.println(min);
}
}
return min;
}
}