继续在我的简单Java程序上找到“找不到符号”,不知道为什么

时间:2016-01-21 16:01:34

标签: java

所以,这是我的代码:

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);

   }
}

编译器继续以粗体显示返回“无法找到符号”错误。我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

在声明之前,不能在Java中使用局部变量。如果您查看代码,可以看到在下一行声明TouchdownNumber之前,您尝试将BallsGivenAway设置为BallsGivenAway

此外:

  • 您是否尝试将BallsGivenAway设置回TouchDownNumber?你定义了两个变量,它们的值应该是......另一个变量?
  • Idiomatic Java使用camelCase变量名,如finalScore,ballsGivenAway。这只是一个风格问题,但你现在也可以习惯它。
相关问题