I'm trying to have the main method call the newGame method but it's giving me an error.
error: cannot find symbol
newGame(answer);
symbol: variable answer
location: class GuessingGame
import java.util.Random;
public class GuessingGame {
public static newGame(int answer){
Random rand = new Random(int answer);
answer = rand.nextInt(51);
}
public static void main (String [] args ){
newGame(answer);
}
}
Your posted code is missing a few things, and doesn't do much. I assume you want to return the new random value from
newGame
(and thus it shouldreturn
anint
). Also, it's better to pass theRandom
to your method (because creating a newRandom
involves seeding it, and if you do it quickly in a loop you can pick the same seed). So, that might look likeThen you need to save the
answer
inmain
. And construct theRandom
. Like,