所以我在一些程序中一直遇到类似的错误,我无法弄明白.循环中的数组和所有变量都是double,所以我不明白为什么它需要一个int值.无论如何,所有的错误都引用了最后一个块中的for语句:
import java.util.Scanner;
public class Exercise610
{ public static void main (String[] args)
{
int smallest;
Scanner stdIn = new Scanner (System.in);
double array1 [] = new double [100];
for (int i=0; array1[i] != -7; i++)
{
System.out.println("Input a value in yer string, or -7 to end");
array1[i] = stdIn.nextDouble();
}
smallest = indexOfSmallestElement(array1);
System.out.println("The smallest value in the array is " + smallest);
}
public static int indexOfSmallestElement (double[] array)
{
int smallestInt;
double smallest = array[0];
for (double …Run Code Online (Sandbox Code Playgroud)