Sunday , 16 December 2018
Home » Class 12 » Java Program for finding Weekday name of the given date

Java Program for finding Weekday name of the given date


Write a program to accept a date in the string format dd/mm/yyyy and accept the name of the day on 1st of January of the corresponding year. Find the day for the given date.



Date : 5/7/2001
Day on 1st January : MONDAY

OUTPUT: Day on 5/7/2001 :  THURSDAY

Programming Code:

* The class Date_DayMethod1 finds the weekday name of a given date
* @author :
* @Program Type : BlueJ Program - Java

class Date_DayMethod1
    public static void main(String args[])throws IOException
        BufferedReader br=new BufferedReader(new InputStreamReader(;
        int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
        String days[]={"","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
        System.out.print("Enter the day : ");
        int d=Integer.parseInt(br.readLine());
        System.out.print("Enter the month : ");
        int m=Integer.parseInt(br.readLine());
        System.out.print("Enter the year : ");
        int y=Integer.parseInt(br.readLine());
        if((y%400==0) || ((y%100!=0)&&(y%4==0)))
        if(m<0 || m>12 || d<0 || d>month[m] || y<0 || y>9999) // Performing Date Validation
            System.out.println("Invalid Date");
            int dn=0;
            for(int i=1;i<m;i++)

            System.out.print("Enter the Day on 1st January in this year: ");
            String s=br.readLine().trim();
            //finding the day of the week which corresponds to the given day name
            int x=0;
            for(int i=1;i<=7;i++)
                if (s.equalsIgnoreCase(days[i]))

            // the main calculation of finding the name of the day of the week of the given date starts here
            for(int i=1;i<dn;i++)
            System.out.print("Output : "+d+"/"+m+"/"+y+" is a "+days[x]);

Check Also

ISC 2017 Computer Science Solution + Examiner’s Comments – From the Council

Solution of ISC 2017 Computer science Paper as provided by the Council for the Indian School Certificate Examinations.

One comment

  1. nice solution

Leave a Reply

Your email address will not be published. Required fields are marked *