Menu
Topics Index
...
`

Day Of Week


If you need explanation Read this topic

If you need Answer Take test on this topic

Day Of Week
What will be the output of the following program?
import java.util.*;
public class DayOfWeek {
    public static void main(String[] a) {
        int day = 1;
        switch (day) {
            case Calendar.MONDAY :
                System.out.print("Mon" + getDay());
            case Calendar.TUESDAY :
                System.out.print("Tues" + getDay());
            case Calendar.WEDNESDAY :
                System.out.println("Wednes" + getDay());
            case Calendar.THURSDAY :
                System.out.print("Thurs" + getDay());
            case Calendar.FRIDAY :
                System.out.print("Fri" + getDay());
            case Calendar.SATURDAY :
                System.out.print("Satur" + getDay());
            case Calendar.SUNDAY :
                System.out.print("Sun" + getDay());
        }
    }
    private static String getDay() {
        return "day~";
    }
}

A. Sunday~
B. Monday~Tuesday~Wednesday~
Thursday~Friday~Saturday~Sunday~
C. Tuesday~Wednesday~
Thursday~Friday~Saturday~Sunday~
D. Compilation Error or Runtime Error
Topic: Calendar In Java - java.util.Calendar Class

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is A. day value is initialized to 1 and Calendar.SUNDAY value is 1. So switch identifies the value of 1 as Calendar.SUNDAY and the statement next to it i.e., Sunday~ is printed..

Posted by Nikhil Sulibhavi    2014-05-01 09:29:14


Ans is A..In general the day of a week of a calendar starts with Sunday and the variable day=1 goes to the case Calendar.Sunday and the getDay() function returns day~..So the answer will be Sunday~

Posted by Badam Swathi    2014-05-01 11:06:34


Congratulations Nikhil Sulibhavi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-02 04:12:23


© meritcampus 2019

All Rights Reserved.

Open In App