所以,这是我的代码:
import java.util.Scanner;
public class FootballsGivenAway
{
public static void main(String [] args)
{
int FinalScore;
**int TouchdownNumber=BallsGivenAway;**
int BallsGivenAway=TouchdownNumber;
Scanner inputDevice= new Scanner(System.in);
System.out.print("What was the final score of the Carolina Panthers? ");
FinalScore=inputDevice.nextInt();
System.out.print("Out of the points the Panthers scored, how many of them were touchdowns? ");
TouchdownNumber=inputDevice.nextInt();
System.out.println("The Carolina Panthers gave away this number of footballs today: " + BallsGivenAway);
}
}
编译器不断在粗体行上返回“找不到符号”错误。我必须做什么来纠正这个问题?
最佳答案
在声明局部变量之前,不能在 Java 中使用它。如果您查看代码,您会发现在下一次声明 BallsGivenAway
之前,您尝试将 TouchdownNumber
设置为 BallsGivenAway
线。
另外:
- 您正在尝试将
BallsGivenAway
设置回TouchDownNumber
吗?您正在定义两个变量,其值应该是...另一个? - 惯用的 Java 使用驼峰命名法变量名称,例如 FinalScore、ballsGivenAway。这只是一个风格问题,但你现在最好习惯它。
关于java - 我的简单 Java 程序不断出现 "Cannot find symbol",但不知道为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34928477/