• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debugging problem

 
Ray Zeigler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I'm trying to resolve this error for the variable "var". I'm trying to have the user type in a port number while executing the program.
For instance
java myprogram 1986

1986 will be the port number that the user specifies.
I keep getting an error for my code below that states
"var cannot be resolved to a variable"


Can someone show me the code of how to do this?




 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because you declared it inside the if-block. as soon as you hit the close curly brace, it falls out of scope, and thus doesn't exist on line 9 anymore. You should do this:



one other thing...if var is going to hold an integer value (like a port number), a 'float' is probably not the best choice.
 
Ray Zeigler
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh really? I've changed it to int. Why is float a bad decision by the way? Thanks for your help!
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Float is used to represent real numbers (not just integers) with low precision. Did you expect people to ask to use port 2.275?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12143
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should choose something that best represents what you are trying to do. You can't have a fractional port - it has to be an integer. Therefore, choosing an integer type makes more sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic