使用Java的第一天,當我將數組索引添加到變量minIndex時,出現for循環中的錯誤。 ()中的值我不確定要輸入什麼內容。我嘗試了我,但那不起作用,並且由於我在java中缺乏知識,我不確定。請給我一些指導。將數組索引號分配給for循環中的變量java
public static int minPosition(double[] list) {
double leastNum;
leastNum = list[0];
// leastNum starts at first number in array
int minIndex;
minIndex = 1;
// minIndex starts at 1 as if first number in Array happens to be the lowest, its index will be one
for (int i = 0; i < list.length; i++)
if (list[i] < leastNum)
leastNum = list[i];
minIndex = list.indexof(i);
return minIndex;
您需要語句塊大括號中的if語句 – scottb 2015-04-06 04:05:14