Problem with an array
My code compiles ok, but when I run the program the output is always 0. It should be the smallest number in the array.
import java.util.Scanner;
publicclass TestSmallestIndex{
static Scanner console =new Scanner(System.in);
publicstaticvoid main(String[] args){
int arraySize;
System.out.print("Enter the size of the array: ");
arraySize = console.nextInt();
int[] listA =newint[arraySize];
System.out.println();
System.out.print("Enter " + listA.length +" integers: ");
for(arraySize = 0; arraySize < listA.length; arraySize++)
listA[arraySize] = console.nextInt();
System.out.println();
System.out.println("The index of the smallest element in the array is: "
+ smallestIndex(listA, listA.length));
}
publicstaticint smallestIndex(int[] list,int size){
int min = 0;
for(int index = 0; index < size; index++){
if(list[index] < list[min] ){
min = index;
}
}
return min;
}
}

