Programming problem at
http://codingbat.com/prob/p187868
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.
sleepIn(false, false) → true
sleepIn(true, false) → false
sleepIn(false, true) → true
My Solution
public class SleepIn {
public boolean sleepIn(boolean weekday, boolean vacation) {
if ((weekday == false) || (vacation == true))
return true;
else
return false;
}
}
The official solution was
public boolean sleepIn(boolean weekday, boolean vacation) {
if (!weekday || vacation) {
return true;
} else {
return false;
}
// This can be shortened to: return(!weekday || vacation);
}
Comparison
I tried to do it too childish way , comparing booleans :P
No comments:
Post a Comment
Please share your views and comments below.
Thank You.