Skip to main content
Code Review

Return to Revisions

2 of 4
Make title represent the code, correct tags.
rolfl
  • 98.1k
  • 17
  • 219
  • 419

Simpler boolean truth table?

I'm doing CodingBat exercise and would like to learn to write code in the most efficient way. On this exercise, I was just wondering if there's a shorter way to write this code.

monkeyTrouble(true, true) → true
monkeyTrouble(false, false) → true
monkeyTrouble(true, false) → false
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {
 
 if (aSmile && bSmile) {
 return true;
 }
 
 if (!aSmile && !bSmile) {
 return true;
 }
 return false; 
}
lang-java

AltStyle によって変換されたページ (->オリジナル) /