Problem:
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".
alarmClock(1, false) → "7:00"
alarmClock(5, false) → "7:00"
alarmClock(0, false) → "10:00"
Solution:
public String alarmClock(int day, boolean vacation) { if (vacation) { if(day > 0 && day != 6) return "10:00"; else return "off"; } else if (day > 0 && day != 6) return "7:00"; else return "10:00"; }
public String alarmClock(int day, boolean vacation) {
ReplyDeleteboolean weekday = day < 6 && day > 0;
if (weekday && !vacation)
return "7:00";
else if ((weekday && vacation) || (!weekday && !vacation))
return "10:00";
return "off";
}
but after running its not showing me output , main method is not there
Deletereturn (vacation ? (day == 0 || day == 6 || day == 7 ? "off" : "10:00") :
ReplyDelete(day >= 1 && day <= 5 ? "7:00" : "10:00"));
These clocks are shaped in the form of grenades and they have extremely loud alarm sounds. kids alarm clock
ReplyDelete//Imdad Momin
ReplyDeletepublic String alarmClock(int day, boolean vacation) {
if(vacation != true) {
return((day>=1 && day<=5)? "7:00" : "10:00" );
}
return((day>=1 && day<=5)? "10:00" : "off" );
}
public String alarmClock(int day, boolean isVacation) {
ReplyDeletefinal boolean isWeekend = (day == 0) != (day == 6);
if (isVacation && isWeekend){
return "off";
}
return (isVacation != isWeekend)? "10:00": "7:00";
}
public String alarmClock(int day, boolean vacation) {
ReplyDeleteif((day>0 && day<6) && !vacation){
return new String("7:00");
}else if((day>0 && day<6) && vacation){
return new String("10:00");
}if(!(day>0 && day<6) && !vacation){
return new String("10:00");
}
return new String("off");
}
boolean weekday = day>0&&day<6;
ReplyDeleteif(weekday&&!vacation) return "7:00";
else if((weekday&&vacation)||(!weekday&&!vacation)) return "10:00";
else return "off";
boolean weekday = day>0&&day<6;
Deleteif(weekday&&!vacation) return "7:00";
else if((weekday&&vacation)||(!weekday&&!vacation)) return "10:00";
else return "off";
public String alarmClock(int day, boolean vacation) {
ReplyDeleteif(!vacation) {
if(day >=1 && day <=5) {
return "7:00";
}
}else if(day == 0 || day == 6){
return "off";
}
return "10:00";
}
public String alarmClock(int day, boolean vacation) {
ReplyDeleteif(vacation){
return day==0 || day==6 ? "off" : "10:00";
}
else{
return day==0 || day==6 ? "10:00" : "7:00";
}
}
public String alarmClock(int day, boolean vacation) {
ReplyDeleteif(!vacation){
if(day > 0 && day <6){
return "7:00";
} else return "10:00";
} else if(day > 0 && day <6){
return "10:00";
} else return "off";
}