Ran my code on intellij with different numbers, and even with the smallest number buried somewhere in the middle of the array. But, I am still getting an error from this. Why is that? I am using the Math.min correctly, and I have found the smallest number. Thanks in advance
package en.codegym.task.pro.task08.task0803;
import java.util.Scanner;
/*
Smallest element of an array
*/
public class Solution {
public static void main(String[] args) {
int[] intArray = getArrayOfTenElements();
System.out.println(min(intArray));
}
public static int min(int[] ints) {
int a = ints [0];
for(int i =0;i< ints.length-1;i++){
a=Math.min(a,ints[i]);
}
return a;
}
public static int[] getArrayOfTenElements() {
Scanner input = new Scanner(System.in);
int [] s = new int [10];
for(int i =0; i<s.length;i++){
s[i]= input.nextInt();
}
return s;
}
}