I was doing an interview and the interviewer told me to write a code to find out if two or more are true when there are three boolean variables
boolean atLeastTwo(boolean a, boolean b, boolean c) {
if ((a && b) || (b && c) || (a && c)) {
return true;
}
else{
return false;
}
}
So I made it like this, and the interviewer asked me if I could make it better, but is that possible?
java boolean boolean-logic
boolean atLeastTwo(boolean a, boolean b, boolean c) {
return a ? (b || c) : (b && c);
}
boolean atLeastTwo(boolean a, boolean b, boolean c) {
return a && (b || c) || (b && c);
}
I think there's a way.
© 2024 OneMinuteCode. All rights reserved.