TechSapphire Tuesday, 2024-03-19, 9:59 AM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • 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

    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2024