• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Assignment for School - error: cannot find symbol  RSS feed

 
Elizabeth Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the process of learning Java. Below is the program that I've been trying to compile, but cannot figure out why 'x' in line 38 provides the following error: 'cannot find symbol'. Any help would be greatly appreciated.




 
Mark King
Ranch Hand
Posts: 55
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
x is declared in the else clause so it won't be available outside the else scope.
 
Jude Niroshan
Ranch Hand
Posts: 132
5
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Declare the x variable outside the for loop. Because you are using it even after the loop closed. That means, beyond the scope of the for loop. Therefore, declare it at the beginning & do the assignment wherever you want(inside the loop, in your case).
 
Elizabeth Jones
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Maneesh Godbole

Apologies! I am new to the whole 'posting code online for help' world. Won't happen again.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!