Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class WorkingDays {
    public static void main(String[] args) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.DAY_OF_MONTH, 7);
        cal.set(Calendar.MONTH, 4);
        cal.set(Calendar.YEAR, 2015);
        System.out.println("Week of month "
                + cal.get(Calendar.WEEK_OF_MONTH));
        System.out.println("Day of week in month "
                + (cal.get(Calendar.DAY_OF_WEEK_IN_MONTH)));
        System.out.println("Day "
                + cal.get(Calendar.DAY_OF_MONTH));
        System.out.println("Month "
                + (Calendar.MAY == cal.get(Calendar.MONTH) ? "May" : "April"));
    }
}


Week of month 2
Day of week in month 1
Day 7
Month May
Week of month 2
Day of week in month 1
Day 7
Month April
Week of month 2
Day of week in month 2
Day 7
Month May
Week of month 2
Day of week in month 2
Day 7
Month April
Compilation Error or Runtime Error

Doubts

Problems

Topic: Calendar In Java - java.util.Calendar Class

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App