Java – an alternative method to compare three ints for equality

int a = 10;
int a = 10;
int b = 10;
int c = 10;

I tried to find out if there was an alternative way to compare three integers or anything equal

My current practice is

if( (a == b) && (a == c) && (b == c)){

}

I wonder if there is another more concise way to do this

Solution

Equality is transitive; You don't need the final comparison B = = C. If a = = B and a = = C, then B = = C

attempt

if ((a == b) && (a == c)){
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>