class rand_number
{
//...
if(rand_n == 2)
{
boolean guessed = true;
}
}
You can only have field declarations at the class level. An if statement like this needs to be in a method, constructor, or initializer block.
You could eliminate the if statement like this:
boolean guessed = rand_n == 2;
But I question why you have any desire to set this value at creation time at all, as opposed to in response to some user action.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…