my dog learned polymorphism
The moose likes Beginning Java and the fly likes Debugging problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Debugging problem" Watch "Debugging problem" New topic
Author

Debugging problem

Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
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

Joined: Oct 02, 2003
Posts: 11882
    
  18

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ray Zeigler
Greenhorn

Joined: Jul 06, 2012
Posts: 18
Oh really? I've changed it to int. Why is float a bad decision by the way? Thanks for your help!
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19758
    
  10

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

Joined: Oct 02, 2003
Posts: 11882
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Debugging problem
 
jQuery in Action, 3rd edition