Results 1 to 3 of 3
  1. #1
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    andnlou2678 is offline Member
    Join Date
    Sep 2011
    Posts
    69
    Rep Power
    0

    Default 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

  1. 10 seconds countdown on console
    By eLancaster in forum New To Java
    Replies: 4
    Last Post: 04-08-2011, 07:46 PM
  2. Replies: 4
    Last Post: 09-09-2010, 12:15 PM
  3. how to get the seconds out of it
    By baktha.thalapathy in forum New To Java
    Replies: 15
    Last Post: 06-09-2010, 04:24 AM
  4. Replies: 3
    Last Post: 04-05-2010, 02:08 PM
  5. Difference in seconds between two times
    By jazzy639 in forum New To Java
    Replies: 11
    Last Post: 09-26-2009, 07:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •