How to find the array index of the lowest value in the array?

Code :

import java.util.Scanner;
class array2{
public static void main(String args[]){
Scanner input = new Scanner(System.in);
int values;
int num[] = new int[10];
System.out.println("Enter 10 values: ");
for(int i=0;i<num.length;i++){
num[i] = input.nextInt();
System.out.print(num[i]+" ");
}
int sum = 0;
for(int j : num){
sum += j;
}
System.out.print("\nThe average is "+sum/10);
int smallest = num[0];
int largest = num[0];
for(int i=1; i< num.length; i++){
if(num[i] > largest){
largest = num[i];
}else if (num[i] < smallest){
smallest = num[i];
}
}
int indexs = smallest.indexOf(smallest);
System.out.println("\nindex of smallest number(s) is "+indexs);
System.out.println("\nSmallest Number is " + smallest);
}
}

I need to get the index position of the lowest values in the array, but the line "int indexs = smallest.indexOf(smallest);" gives me an error. How do you fix it?

Re: How to find the array index of the lowest value in the array?

There is no indexOf method of primitive int which is the dataType of smallest and hence you are getting the error. You need to loop through the entire array and find out the value which is lowest and its corresponding index.

Re: How to find the array index of the lowest value in the array?

Quote:

gives me an error.

Please copy the full text of the error message and paste it here. It has important info about the error.