Thunder Dash
Thunder Dash

Reputation: 1

Keep on getting a "Cannot find symbol" on my simple Java program and don't know why

So, here's my code:

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

   }
}

The compiler keeps returning the "Cannot find symbol" error on the line in bold. What must I do to correct this issue?

Upvotes: 0

Views: 41

Answers (1)

Geoffrey Wiseman
Geoffrey Wiseman

Reputation: 5637

You can't use a local variable in Java before you've declared it. If you look at your code, you can see that you're trying to set TouchdownNumber to BallsGivenAway before you've declared BallsGivenAway on the next line.

Also:

  • You're trying to set BallsGivenAway back to TouchDownNumber? You're defining two variables whose value is supposed to be ... the other one?
  • Idiomatic Java uses camelCase variable names like finalScore, ballsGivenAway. It's just a style issue, but you might as well get used to it now.

Upvotes: 1

Related Questions