Results 1 to 3 of 3
Thread: java seconds program
- 10-12-2011, 10:02 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 69
- Rep Power
- 0
java seconds program
hi its me again
i have another program i am doing and wounderd if somebody could check if this answer is ok.
and also could somebody explain how i would do an analysis of this problem and also the calculations to show expected results for 3793 seconds.
Write a program to prompt the user for a positive integer number of seconds and output the number of hours, minutes and seconds that it represents. Test your program with 3793 seconds.
code
import java.util.Scanner;
public class Seconds
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Input number of seconds: ");
int seconds = scanner.nextInt();
int hours = seconds / 3600;
seconds = seconds % 3600;
int minutes = seconds / 60;
seconds = seconds % 60;
System.out.println("hours = "+hours);
System.out.println("minutes = "+minutes);
System.out.println("seconds = "+seconds);
}
}
results
H:\FPT>java Seconds
Input number of seconds: 3793
hours = 1
minutes = 3
seconds = 13
many thanks Andy..
lts
-
Re: java seconds program
Is your answer correct when you check it with a calculator?
- 10-12-2011, 10:31 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 69
- Rep Power
- 0
Re: java seconds program
hi not sure how to work this out on a calculator i kind of get how it works
user enters 7680 secs.
(1 hr / 3600 secs) * (7680 secs) = 2 hrs
7680 - (3600 * 2) = 480 secs leftover
To get the leftover you could also do 7680%3600 = 480
(1 min / 60 secs) * (480 secs) = 8 mins
but to put this in a calculator ?
Similar Threads
-
10 seconds countdown on console
By eLancaster in forum New To JavaReplies: 4Last Post: 04-08-2011, 06:46 PM -
Finding epoch seconds and separate yera,month,day,hr,min and seconds
By sathish kumar in forum New To JavaReplies: 4Last Post: 09-09-2010, 11:15 AM -
how to get the seconds out of it
By baktha.thalapathy in forum New To JavaReplies: 15Last Post: 06-09-2010, 03:24 AM -
a constructor to convert seconds to hours, min & seconds
By senca in forum New To JavaReplies: 3Last Post: 04-05-2010, 01:08 PM -
Difference in seconds between two times
By jazzy639 in forum New To JavaReplies: 11Last Post: 09-26-2009, 06:58 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks