Access over 20 million homework & study documents
search

A day has 86,400 secs (24 hrs 60 mins 60 secs) In a file called

Content type

User Generated

Rating

Showing Page:
1/3
A day has 86,400 secs (24 hrs * 60 mins * 60 secs). In a
file called task1.java, write a program that: Prompts the
user for an integer, specifying a number of seconds in the
range 1 to 86,400. Outputs the time as hours, minutes, and
seconds with a 24-hour clock. If the user inputs an integer
that is less than 1 or greater than 86,400, your program
should print \"Invalid number of seconds, must be between
1 and 86400.\" You can divide the user\'s value by 3600
(the number of seconds in an hour) to determine the
number of hours, and then divide the remainder of that
operation by 60 (the number of seconds in a minute) to
calculate the number of minutes. The remainder of that
operation will be the number of seconds. For example, this
is how your program would work step by step, if the user
enters 70000: Prompt the user for a value in the range 1 to
86,400. The user inputs 70000 for this example. Divide the
user input by 3600 to get 19 (hrs) Get the remainder of the
above operation: there are 1600 seconds left over. Divide
that remainder by 60 to get 26 (mins) Get the remainder of
the above operation: there are 40 seconds left over.
Therefore, we have 19 hours, 26 minutes, and 40 seconds.
For example: if the user enters 70000, your program output
should look EXACTLY like this: Please specify the number
of seconds (between 1 and 86400): 70000 70000 seconds
correspond to 19 hours, 26 minutes, and 40 seconds.
Solution

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
import java.util.Scanner;
public class Task1 {
public static void main(String[] args) {
int sec,hour,min;
int seconds;
Scanner s=new Scanner(System.in);
System.out.println(\"Please specify the number of seconds
(between 1 and 86400): \");
seconds=s.nextInt();
if(seconds<1 || seconds>86400)
{
System.out.println(\"Invalid number of seconds, must be
between 1 and 86400.\");
}
else
{
hour=seconds/3600;
min=(seconds%3600)/60;
sec=(seconds%3600)%60;
System.out.println(seconds+\" seconds correspond to
\"+hour+\" hours, \"+min+\" minutes, and \"+sec+\"
seconds.\");
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up

Unformatted Attachment Preview

A day has 86,400 secs (24 hrs * 60 mins * 60 secs). In a file called task1.java, write a program that: Prompts the user for an integer, specifying a number of seconds in the range 1 to 86,400. Outputs the time as hours, minutes, and seconds with a 24-hour clock. If the user inputs an integer that is less than 1 or greater than 86,400, your program should print \"Invalid number of seconds, must be between 1 and 86400.\" You can divide the user\'s value by 3600 (the number of seconds in an hour) to de termine the number of hours, and then divide the remainder of that operation by 60 (the number of seconds in a minute) to calculate the number of minutes. The remainder of that operation will be the number of seconds. For example, this is how your program would work step by step, if the user enters 70000: Prompt the user for a value in the range 1 to 86,400. The user inputs 70000 for this exa ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Excellent! Definitely coming back for more study materials.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4