Question

(Java) Ask the user for the elapsed time of a concert in seconds. Find and display...

(Java) Ask the user for the elapsed time of a concert in seconds. Find and display the time in hours, minutes and seconds. For example, if the user enters 9630 seconds, then the output is 2 hours, 40 minutes and 30 seconds.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class SecondsToHours {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number of seconds: ");
        int seconds = in.nextInt();

        int h = seconds / 3600;
        seconds %= 3600;
        int m = seconds / 60;
        seconds %= 60;

        System.out.printf("%d hours, %d minutes and %d seconds\n", h, m, seconds);
    }
}
Add a comment
Know the answer?
Add Answer to:
(Java) Ask the user for the elapsed time of a concert in seconds. Find and display...
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
  • 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.)

  • 12. 13. Write a program that prompts the capacity, in gallons, of an automobile fuel tank...

    12. 13. Write a program that prompts the capacity, in gallons, of an automobile fuel tank and the miles per gallon the automobile can be driven. The program outputs the number of miles the automobile can be driven without refueling 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...

  • in java, Ask the user for a string. Display the number of whitespace characters in that...

    in java, Ask the user for a string. Display the number of whitespace characters in that string. Standard Input: this is a test Required Output: Enter a String\n Number of whitespace characters: 3\n

  • 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...

  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a...

    Time can be expressed in [hours, minutes, seconds]. Create a program in C++ that takes a current time and adds an elapsed time to compute the future time. NOTE: hours are expressed using the 24 hours clock. For example, if the current time is 17, 34, 56 and the elapsed time is 9, 48, 17 then the future time is 3, 23, 13. You should have variables cth, ctm, cts, eth, etm, ets, fth, ftm, fts, representing the current/elapsed/future hours/minutes/seconds.

  • (Java) HELP! Create a program that will ask the user to enter their first name and...

    (Java) HELP! Create a program that will ask the user to enter their first name and their favorite number. Ask the user if they would like the information repeated back to them. If they type "Y" display the answers back to them. If they type anything else, display the word "Goodbye". An example of what your output window should look like is below. The system-generated output is in red. The user-provided input is in green. (Your actual program will only...

  • Pythpn #Exercise 1 #Ask the user for a three letter word using the prompt: three letter...

    Pythpn #Exercise 1 #Ask the user for a three letter word using the prompt: three letter word? (include a space after the ?) #Display the entire word #Display the word vertically, one letter at a time using print statements and the string index #For example, if the user enters baa, the output should be (ignore # signs): #baa #b #a #a #Exercise 2 #Ask the user for a number using the prompt: first number? (include a space after the ?)...

  • Ask the user to enter a message Ask the user how many time they want to...

    Ask the user to enter a message Ask the user how many time they want to print the message Then use "while","do-while" and "for" loop to print the message. Show the number at the beginning of the lines when printing. For example: Enter your message: Welcome to Java How many time you want to print this message: 3 Using "while" loop: 1=> Welcome to Java 2=> Welcome to Java 3=> Welcome to Java Using "do-while" loop: 1=> Welcome to Java...

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