Java Question Set I – Conditional Statements in Java

7. Write a program that converts total seconds (given by the user through a prompt) into days, hours, minutes, and seconds.

Example to understand the question:

You entered 500,000 seconds, it should output that 500,000 are same as 5 days, 18 hours, 53 minutes and 20 seconds.

Logic of the Program:

  1. Divide the input by 86400, if you get a number greater than 0, this is the number of days.
  2. Again, divide the remained number you get from the first calculation by 3600, this will give you the number of hours
  3. Divide the remainder of your second calculation by 60 which is the number of Minutes
  4. Finally the remained number from your third calculation is the number of seconds



0 Responses on Java Question Set I - Conditional Statements in Java|

Leave a Message

Your email address will not be published. Required fields are marked *

CommentLuv badge

Pin It on Pinterest