Я пишу код для класса, который должен принимать экзамены в качестве входных данных, пока пользователь не вводит «-1». После того, как они уходят, он усредняет результаты и печатает их. Я продолжаю получать ошибку «не могу найти символ», и я просмотрел сайт и пока не нашел ничего подходящего.JAVA- ошибка: не найден символ - не нашли ответа на сайте
import java.util.*;
public class hw6
{
public static void main(String args[])
{
int avg = 0;
Scanner in = new Scanner(System.in);
System.out.println("This program will intake exam scores between 0 and 100 ONLY.");
System.out.println("Enter scores to average, and when you're done inputting, ");
System.out.println("enter -1 to stop and average your scores.");
int scoreIn = in.nextInt;
getLegalInput(scoreIn);
System.out.println("The average of the exam scores is " + avg + ".");
}
public static int getLegalInput (int scoreIn)
{
int sum = 0;
int i = 0;
while (scoreIn != -1)
{
if ((scoreIn < 101) && (scoreIn > -1))
{
sum = (sum + scoreIn);
i++;
}
else
System.out.println("Out of range! Must be between 0 and 100.");
}
if (scoreIn == -1)
{
CalcAvg(sum, i);
}
}
public static int CalcAvg(int sum, int i)
{
int avg = 0;
i = (i - 1); //fix problem where the stop value is included in the i value
//calc = (calc - Svalue); // fixes problem where stop value throws off the calc
avg = (sum/i); //averages the values of exam
return (avg);
}
}
Ошибка я получаю:
hw6.java:14: error: cannot find symbol
int scoreIn = in.nextInt;
^
symbol: variable nextInt
location: variable in of type Scanner
1 error
Вся помощь и советы оценили!
'in.nextInt();' – Eran
О, боже, я не могу поверить, что я пропустил что-то такое хромое. Спасибо –
Ваш код не будет компилироваться после исправления in.nextInt(). Добавьте оператор return в метод! – FallAndLearn