Knowee
Questions
Features
Study Tools

What will be the output of the following program?        Calendar cal = Calendar.getInstance();        cal.set(Calendar.HOUR, 23);        cal.set(Calendar.MINUTE, 58);        cal.set(Calendar.SECOND, 59);        System.out.print(cal.get(Calendar.HOUR) + ":");        System.out.print(cal.get(Calendar.MINUTE) + ":");        System.out.print(cal.get(Calendar.SECOND));

Question

What will be the output of the following program?        Calendar cal = Calendar.getInstance();        cal.set(Calendar.HOUR, 23);        cal.set(Calendar.MINUTE, 58);        cal.set(Calendar.SECOND, 59);        System.out.print(cal.get(Calendar.HOUR) + ":");        System.out.print(cal.get(Calendar.MINUTE) + ":");        System.out.print(cal.get(Calendar.SECOND));

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be: 23:58:59

This is because the Calendar instance 'cal' is set to the time 23:58:59. When these values are retrieved using cal.get() and printed, they will display the time that was set.

Similar Questions

What will be the output of the following program?        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"));

What will be the output when the following code is executed?public class Product {public static void main(String[] args) {                             LocalDate startLocalDate = LocalDate.of(2016, Month.JUNE, 01);LocalDate tempLocalDate = startLocalDate;startLocalDate.plusDays(10);System.out.println(tempLocalDate);}} 2016-06-0101-06-20162016-06-1111-06-2016

Select the correct answerWhat will be the output of the following Java program?import java.lang.System;  class Output  {     public static void main(String args[])     {       long ct1, ct2;         ct1 = System.currentTimeMillis();       for (int j = 0; j < 10000000; j++);       ct2 = System.currentTimeMillis();       System.out.print(ct1 - ct2);     }  }Options101000System Dependent

Consider the following programimport java.time.*;public class TestParseMethod{  public static void main(String[] args){  String dateString = "2/4/2019";  LocalDate myDate = LocalDate.parse(dateString);  System.out.println("You entered " + myDate);}}What will be an output of this program ?Group of answer choicesYou entered 2 Apr 2019It will not compileYou entered 2/4/2019It will create exception

What is the output of this code?int time = 20;(time < 18) ? printf("Good day") ; printf("Good evening");Group of answer choicesGood dayGood eveningNone of the above

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.