Given a day of the week encoded as 0=Sun, 1=Mon, 2=Tue, ...6=Sat, and a boolean indicating if we are on vacation, return a string of the form "7:00" indicating when the alarm clock should ring. Weekdays, the alarm should be "7:00" and on the weekend it should be "10:00". Unless we are on vacation -- then on weekdays it should be "10:00" and weekends it should be "off"
larmClock(1, false) → "7:00"
alarmClock(5, false) → "7:00" alarmClock(0, false) → "10:00"
mamy warunek isVacation true or false ktory determinuje ktorym torem pojdziemy.
Instrukcja warunkowa powinna ten warunek sprawdzic jako pierwszy.
if (isVacation){
.
.
.
}
else
{
.
.
.
}
|
public String alarmClock(int day, boolean vacation) { if(vacation) { if(day == 0 || day == 6) return "off"; return "10:00"; } else { if(day == 0 || day == 6) return "10:00"; return "7:00"; } }
Kolejny przykład: if outsideMode true than;
public boolean in1To10(int n, boolean outsideMode) { if (outsideMode){ if(n<=1 || n>=10){ return true; } } else { if(n>=1 && n<=10){ return true; } }return false; }
Komentarze
Prześlij komentarz