Reputation: 15
I want to do boolean check like this.This doesn't work. But my idea is like this
if(num==(1,2,3)){
println (num)
}
or
if(num==(1|2|3)){
println (num)
}
How can I do this?
Upvotes: 0
Views: 75
Reputation: 234715
num==(1,2,3)
is not a valid expression in Java. (Although in C and C++ it is equivalent to num == 3
).
You need to write if (num == 1 || num == 2 || num == 3)
.
If num
is an integral type, you could use if (num >= 1 && num <= 3)
.
Upvotes: 1