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?
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?
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).