Java, похоже, думает, что я пытаюсь преобразовать или выполнить какое-то действие по одной из моих двойных переменных. Я получаю сообщение об ошибкенесовместимые типы - double to int?
average2.java:23: error: incompatible types: possible lossy conversion from double to int scores[count++]=score;
Я действительно запутался в том, что я ничего как целое не объявлены до сих пор, - каждая переменная является двойной, потому что я ожидаю, чтобы иметь некоторые десятичные. Ниже мой код:
public static void main (String [] args)
{
double numOf;
double lowest = 100;
double count = 0;
double sum = 0;
double average = 0;
double score;
double scores[] = new double[100]; //[IO.readDouble("Enter Scores, Enter -1 to Quit")];
while ((count <100) &&((score =IO.readDouble("Enter Scores, (-1 to Quit")) > 0));
{
scores[count++]=score;
}
//This section obtains the highest number that was entered`
double max = scores[0];
for (double i=0; i<scores.length; i++)
if(max < scores[i])max =scores[i];
System.out.println("Maximum is " + max);
// This section obtains the lowest score entered
double min = scores[0];
for (int i=0; i<scores.length; i++)
if (min > scores[i]) min = scores [i];
int sumOf =0;
for (int i=0; i < scores.length; i++)
{
sumOf += scores[i];
}
System.out.println("The sum of all scores is " + sumOf);
System.out.println("Minimum is " + min);
count = count + 1;
average = (sumOf/scores.length);
System.out.println("Average is " + average);
} //end main
} //end class
Просто смените счет на int. Это решит вашу проблему. – StackFlowed