If equivalent without using conditional operations and other loop methods java -


int function(int a, int b, int c){         if(a==c)             return a;         else              return b;     } 

question achieve same o/p without using if, while, do, for, switch,conditional expression(?:) , other general inbuilt methods equals

please tell me logic , code..

here's approach using operators only:

int function(int a, int b, int c) {     //if == c: result = 0x00000000     //else:      result = 0xffffffff     int result = (a - c | c - a) >> 31;      //if == c: result = 0x00000000 & (a ^ b) = 0     //else:      result = 0xffffffff & (a ^ b) = ^ b     result &= ^ b;      //if == c: result = 0       ^ =     //else:      result = (a ^ b) ^ = b     result ^= a;      return result; } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -