alternative way to compare if three ints are equal

20,318

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)){
Share:
20,318
user3059427
Author by

user3059427

Updated on August 05, 2022

Comments

  • user3059427
    user3059427 over 1 year
    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.