Question : 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, print 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".
Output:
1 false -> 7:00
0 false -> 10:00
0 true -> off
5 true -> 10:00
Answer :
import java.util.*;
public class AlarmCode
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Day Code : ");
int DayCode=sc.nextInt();
System.out.println("Vacation : ");
boolean IsVacation=sc.nextBoolean();
if(DayCode==6 || DayCode==0)
{
if(!IsVacation)
{
System.out.println("10:00");
}
else
{
System.out.println("Off");
}
}
else if(DayCode<6)
{
if(!IsVacation)
{
System.out.println("7:00");
}
else
{
System.out.println("10:00");
}
}
else{
System.out.println("Invalid Code");
}
}
}
Click to download
|