我正在編寫一個代碼,應該將考試分數作爲輸入,直到用戶輸入'-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