Question

JAVA Write a complete program that prompts the user to provide a time span expressed in...

JAVA Write a complete program that prompts the user to provide a time span expressed in seconds from keyboard, gets the input, then converts the seconds to the time expressed in days, hours, and minutes and seconds in that order, and output them in a readable format of your choice. For example, suppose the input for seconds is 3662, your program should figure out that it is equivalent to 0 day, 1 hour, 1 minute and 2 seconds. So your program should report the following outputon screen: 0 day(s) 1 hour(s), 1 minute(s), and 2 second(s). Here are some facts (conversion constants) you need to know. 1 day=24 hours. 1 hour=60 minutes, and 1 minute=60 seconds.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
class TimeDemo
{
public static void main(String[] args)
{
   Scanner input=new Scanner(System.in);
   System.out.println("Enter time span in seconds");
   int span=input.nextInt();
   int days=span/86400;
   span=span%86400;
   int hours=span/3600;
   span=span%3600;
   int minutes=span/60;
   span=span%60;
   int seconds=span;
   System.out.println(days+" day(s) "+hours+" hour(s), "+minutes+" minute(s), and "+seconds+" second(s)");
}
}

Output

C:\Users\hp>java TimeDemo
Enter time span in seconds
3662
0 day(s) 1 hour(s), 1 minute(s), and 2 second(s)

C:\Users\hp>java TimeDemo
Enter time span in seconds
129600
1 day(s) 12 hour(s), 0 minute(s), and 0 second(s)

Add a comment
Know the answer?
Add Answer to:
JAVA Write a complete program that prompts the user to provide a time span expressed in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 01: Write a Java program that prompts for and reads the latitude of a location...

    Question 01: Write a Java program that prompts for and reads the latitude of a location on earth in the format:                    integerDegrees           integerMinutes       doubleSeconds     characterPosition where characterPosition is either N, n, S or s. If the input is valid your program converts the input latitude to decimal degrees where North latitudes are +ve, and South latitudes are –ve. 26 13 15.272400 N 26.220909 50 11 55.024800 S -50.198618 25 44 36.97 s -25.743603 43 10 23.49 n 43.173192 :...

  • C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as...

    C++ Question 6 (10pt): Convert seconds Write a program that takes a number of seconds as user input (as an integer) and converts it to hours, minutes, and seconds as shown below. You should convert the amount of time in such a way that maximizes the whole numbers of hours and minutes. Expected output 1 (bold is user input) Enter a number of seconds: 60 0 hour(s) 1 minute(s) 0 second(s) Expected output 2 (bold is user input) Enter a...

  • in c++ program Write a C + + program that prompts the user to input the...

    in c++ program Write a C + + program that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example, if the elapsed time is 9630 seconds, then the output is 2:40:30.)

  • HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number...

    HELP IN JAVA: WHILE LOOP: Write a program that asks the user to enter a number of seconds. This number should be less than or equal to 32767 because that is the largest number pep8 can handle. Your program should then output the number of hours, minutes, and seconds on the planet of Crypton, where there are 64 seconds in a minute and 32 minutes in an hour.

  • In JAVA, please: Write a program that draws a clock face with a time that the...

    In JAVA, please: Write a program that draws a clock face with a time that the user enters in two text fields (one for the hours, one for the minutes). Hint: You need to determine the angles of the hour hand and the minute hand. The angle of the minute hand is easy; the minute hand travels 360 degrees in 60 minutes. The angle of the hour hand is harder; it travels 360 degrees in 12 × 60 minutes.

  • Python Please help Write a program that asks the user to enter a number of seconds...

    Python Please help Write a program that asks the user to enter a number of seconds and then prints the same amount of time in days, hours, minutes, and seconds. For example, 3667 seconds is equivalent to 0 days, 1 hour, 1 minute, and 7 seconds. Print out the result in the format: "0 day(s), 1 hour(s), 1 minute(s), and 7 second(s)." SAMPLE RUN #4: python3 TimeCalculator.py Interactive SessionStandard InputStandard Error (empty)Standard Output Hide Invisibles Highlight: NoneStandard Input OnlyPrompts OnlyStandard...

  • Write java program that prompts the user to enter integers from the keyboard one at a...

    Write java program that prompts the user to enter integers from the keyboard one at a time. Program stops reading integers once the user enters the same value three times consecutively. Program then outputs "Same entered 3 in a row. "

  • Build a java program to validate a date in the future as entered by the user...

    Build a java program to validate a date in the future as entered by the user at the keyboard as three separate integer values: mm dd yyy Acceptable data criteria: 1. mm: month in range of 1-12 2. dd: day in range of 1-30 for April, June. September, & Nov. / 1-31 January, March, May, July, August, October, & December. Only accept 1-28 for February at this point. 3. yyy: current year (as long as the month and day have...

  • Write a program that asks the user to enter a number ofseconds.• There are...

    Starting Out with C++ (9th Edition)  Chapter 4, Problem 7PCWrite a program that asks the user to enter a number of seconds.• There are 86400 seconds in a day. If the number of seconds entered by the user is greater than or equal to 86400, the program should display the number of days in that many seconds.• There are 3600 seconds in an hour. If the number of seconds entered by the user is less than 86400, but is greater...

  • in java 3) Sum. Write a program that prompts the user to read two integers and...

    in java 3) Sum. Write a program that prompts the user to read two integers and displays their sum. Your program should prompt the user to read the number again if the input is incorrect.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT