When I try to define an integer or attempt to define a range of integers in an if-statement, it returns an error message saying "Unreachable code"
I've tried a few different methods, such as changing the if-statement to
if (rand == 33)
if (rand.nextInt == 33)
which returns the error message "incompatible operand types Random and Int", "nextInt cannot be resolved or is not a field" respectively.
Then I tried
if (rand.nextInt() == 33)
which then spat back "unreachable code".
And for the range issue I tried 33-0, 0-33 which doesnt work.
public static void main(String args[]){
System.out.println("Random Integers:"+computeRandom());
}
public static int computeRandom() {
//create instance of Random class
Random rand = new Random();
//Generate random integers in range 0 to 100
rand.nextInt(101); //83
return rand.nextInt();
if (rand.nextInt() == 33) {
}
I expect it to eventually return the letter "A" depending on what range it falls under at the moment the range is intended to be 0-33.
Aucun commentaire:
Enregistrer un commentaire