w3resource
Java Programming Exercies

Java Exercises: Reads a date and prints the day of the date

Java Basic: Exercise-225 with Solution

Write a Java program to that reads a date (from 2004/1/1 to 2004/12/31) and prints the day of the date. Jan. 1, 2004, is Thrusday. Note that 2004 is a leap year.

Pictorial Presentation:

Java Basic Exercises: Reads a date and prints the day of the date.

Sample Solution:

Java Code:

import java.util.*;
 
class Main {
 
    static int days[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    static String name[] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
 
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
		System.out.println("Input month and date(o o to exit)");
		
        for(;;){
            int m=in.nextInt(), d=in.nextInt();
            if(m==0&&d==0) break;
            System.out.println(solve(m,d));
        }
    }
 
    static String solve(int month, int date){
        int cur = 3;
		System.out.println("Name of the day:");
        for(int i=0; i

Sample Output:

Input month and date(o o to exit)
9
15
Name of the day:
Wednesday

Flowchart:

Flowchart: Reads a date and prints the day of the date.

Java Code Editor:

Contribute your code and comments through Disqus.

Previous:Write a Java program to test the followings.
Next: Write a Java program to print mode values from a given a sequence of integers. The mode value is the element which occurs most frequently. If there are several mode values, print them in ascending order.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming