Reputation: 701
Is it possible to simplify the following statement using && or ||, or even & or | or ^?
int result = A ? (B ? 1 : -1) : (B ? -1 : 1);
I believe I could assign a temporary variable like so:
boolean C = B ? A : !A; // Also: is it correct that this can be simplified to !(A ^ B)?
And then do:
int result = C ? 1 : -1;
But I'm curious if it's possible without a temporary variable.
Upvotes: 0
Views: 53