Thursday, 25 August 2016

Java program to accept the date and print the week name

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution {

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String month = in.next();
    String day = in.next();
    String year = in.next();

    Calendar calendar = Calendar.getInstance();
    calendar.set(Integer.parseInt(year), Integer.parseInt(month) - 1, Integer.parseInt(day));

    String dayOfWeek = calendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.US);

    System.out.print(dayOfWeek.toUpperCase());

}
}
Sample Input
08 05 2015
Sample Output
WEDNESDAY

No comments: