Write a java program to find the day of birth

Given an input as the date of birth of the person, write a program to calculate on which day (MONDAY, TUESDAY….) he was born to store and print the day in Upper Case letters.

The return type of the output is a string which should be the day in which the person was born.

Input and Output Format:

NOTE: date format should be(dd-MM-yyyy)
Input consists a date string.

The output is a string which the day in which the person was born.

Refer sample output for formatting specifications.

Sample Input 1:

29-07-2013

Sample Output 1:

MONDAY

Sample Input 2:

14-12-1992

Sample Output 2:

MONDAY

Find the day of birth in Java.

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws ParseException {

    Scanner sc = new Scanner(System.in);
    String s1 = sc.nextLine();
    System.out.println(calculateBornDay(s1));
  }

  public static String calculateBornDay(String s1) throws ParseException {
    SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
    SimpleDateFormat sdf1 = new SimpleDateFormat("EEEEE");
    Date d = sdf.parse(s1);
    String s = sdf1.format(d);
    return s.toUpperCase();
  }
}

Add a Comment

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

5 × three =