I have a class that generates a random number within a given interval.
public class Dice{
//code.....
public int throwDice(){
Random randomGen = new Random();
int min = 1;
int max = sides; //sides gets a value earlier in the class
int randomNum = randomGen.nextInt((max - min) + 1) + min;
return randomNum;
}
Then the assignment says that I'm going to use a boolean
method that looks like this (with my already written code in it as well):
private boolean step(){
int res = this.dice.throwDice();
int startpos = this.bridge.getFirst();
if (res == 10){ //this works
return false;
}
else if (res => 7 && res <= 9 ){ //but the error occurs here
//code....
return true;
}
What I need to do is check if the generated random number in the throwDice()
method is within a certain interval of numbers.
The problem is that I get an error that says that I can't convert an int
to a boolean
. Is there a way to get around this? Or do I have to rethink my whole solution?
=>
should be the other way around.
else if (res => 7 && res <= 9 ){
should be
else if (res >= 7 && res <= 9 ){
Equality and Relational Operators
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to <-----
< Less than
<= Less than or equal to
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.