Computer Science, asked by mraggressive2005, 11 months ago

Write a program in Java to input the day on January 1 and the corresponding year. Now find the day on November 30 of that year.

Example 1:
INPUT:
Day on January 1: Tuesday
Year: 2019
OUTPUT:
Saturday



Example 2:
INPUT:
Day on January 1: Monday
Year: 2018
OUTPUT:
Friday

Answers

Answered by Paulian42
1

import java.io.*;

class DayFinder

{

   public static void main(String args[])throws IOException

{

       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

       System.out.print("Day on January 1: ");

       String day = br.readLine();

       int start = 0;

       System.out.print("Year: ");

       int year = Integer.parseInt(br.readLine());

       boolean isLeap = false;

       if(year % 400 == 0)

           isLeap = true;

       else if(year % 100 != 0 && year % 4 == 0)

           isLeap = true;

       int days = 30 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

       if(isLeap)

           days++;

       String wd[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

       if(day.equalsIgnoreCase("Sunday"))

           start = 0;

       else if(day.equalsIgnoreCase("Monday"))

           start = 1;

       else if(day.equalsIgnoreCase("Tuesday"))

           start = 2;

       else if(day.equalsIgnoreCase("Wednesday"))

           start = 3;

       else if(day.equalsIgnoreCase("Thursday"))

           start = 4;

       else if(day.equalsIgnoreCase("Friday"))

           start = 5;

       else if(day.equalsIgnoreCase("Saturday"))

           start = 6;

       else{

           System.out.println("Invalid Day!");

           return;

       }

       for(int i = 1; i <= days; i++)

           start = (start + 1) % 7;

       String result = wd[start];

       System.out.println(result);

   }

}

Mark The brainliest

Similar questions