This program's supposed your typical random number generator. It doesn't seem to be passing the int Number back from the NumbertoGuess method for use in the rest of the program. What am I doing wrong here? I'm aware there are some missing things in this program, I'm concerned about getting the value returned properly right now.
I've been doing some debugging with Ststem.out.println and trying to track the variables and their values as the program runs. If you execute the code, it will let you pick a number but will always tell you the number is lower than your guess. When you guess either a 0 or guess twice, it says you've guessed correctly and asks if you'd like to play again.
Far as I can tell, it's not passing the randomized Number variable back into the public void main for use in the next method in the series once it's generated in NumbertoGuess. I see the number generated correctly within NumbertoGuess but always see a value of 0 with a println at line 15 or 16 when I check it.
Joined: Aug 05, 2005
Java is pass by value, so passing Number as a parameter to the method will not cause Number to be changed.
What you should have is
Note that I've changed the name of the variable in NumbertoGuess to make it obvious that it is not the same variable as the Number instance variable
Joined: May 12, 2009
Alright, that makes sense. So how do I get the value of num out of the method for use in the rest of the program? Does the returning of num pass that value as the int num or back to NumbertoGuess?
Joined: Apr 22, 2009
Your have several problems with this code...
1 You don't adhere to Sun's naming recommendations.