所以,这是我的代码:
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中使用局部变量。如果看一下代码,可以看到您在尝试在下一行声明TouchdownNumber
之前将BallsGivenAway
设置为BallsGivenAway
。
也:
您试图将BallsGivenAway
设置回TouchDownNumber
吗?您正在定义两个变量,其值应为...另一个?
惯用的Java使用camelCase变量名,例如finalScore,ballsGivenAway。这只是一个样式问题,但是您现在也应该习惯它。