So I keep getting errors similar to this in a few programs and I can't quite figure it out. The array and all variables in the loop are double, so I don't get why it expects an int value. Anyway here it is, all the errors refer to the for statement in the last block:
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 u: array)
{
if (array[u+1] < array[u])
{
smallest = array[u+1];
}
}
smallestInt = (int) smallest;
return smallestInt;
}
}
File: /Users/Crbn/introcs/Exercise610.java [line: 33]
Error: /Users/Crbn/introcs/Exercise610.java:33: possible loss of precision
found : double
required: int
File: /Users/Crbn/introcs/Exercise610.java [line: 33]
Error: /Users/Crbn/introcs/Exercise610.java:33: possible loss of precision
found : double
required: int
File: /Users/Crbn/introcs/Exercise610.java [line: 35]
Error: /Users/Crbn/introcs/Exercise610.java:35: possible loss of precision
found : double
required: int