Find the Day on November 30

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

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);
    }
}

1 thought on “Find the Day on November 30

  1. Sir,a program is given which states that:
    A class AdharCard contains the adhar number and name of n no.of persons.Some of the data members/member functions are given below:
    Data Member:
    adhar[]=long integer array to store Adhar Numbers
    nm[]:String array to store names of persons
    Member Function:
    AadharCard(int):Parameterised constructor to store number of persons
    void input():to enter Adhar Number and names of persons in ascending order of Adhar Number
    void display():to display the Adhar Number and Name in the format:
    AdharNo. Name
    – –
    boolean bsearch(long):to search for a particular adhar number using Binary Search Technique by recursive function.If found it returns true or false and displays the details of the person.
    Specify the class giving details of all member functions Adharcard(int),void input(),void display(),boolean bsearch(long).Define the main() function to create an object and call the functions accordingly.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.