Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alternative way to compare if three ints are equal

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

I am trying to find out if there is alternate way to compare if three ints or anything are equal.

The way i am currently doing is

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

}

I was wondering if there is an alternate and more concise way to do this.

like image 540
user3059427 Avatar asked Dec 12 '13 01:12

user3059427


1 Answers

Equality is transitive; you don't need the last comparison b == c. If a == b and a == c, then b == c.

Try

if ((a == b) && (a == c)){
like image 162
rgettman Avatar answered Oct 14 '22 08:10

rgettman