Results 1 to 2 of 2
  1. #1
    lbayne is offline Member
    Join Date
    Sep 2010
    Rep Power

    Question How to read user input in hh:mm:ss without time class

    I am trying to design and implement a Java application that calculates and displays the elapsed time between two time values expressed in the 24-hour notation with the form hh:mm:ss. Assuming that the two times occur on the same day and that the “start” time occurs before the “finish” time. A typical program execution would look like the following:

    Enter the start time (hh:mm:ss): 07:10:50
    Enter the finish time (hh:mm:ss): 13:45:09

    Elapsed Time = 06:34:19

    I am not to use any of the Java Time Class functions. This is an exercise in string processing and algorithm development. The output should be formatted as shown(hh:mm:ss). The appropriate leading zeros need to be included.

    The question is: What commands do I use to read in the time in hh:mm:ss format without using a Java Time Class function?

    I've tried Scanner sc = new Scanner (;

    It is not working and I don't know how to handle the colons.:confused:

    Any help is appreciated.
    Last edited by lbayne; 09-30-2010 at 02:09 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    Read the hh:mm:ss format as a String and parse it to three Strings using split or indexOf or StringTokenizer. Then convert the three strings to ints.

Similar Threads

  1. Read user input into integer array
    By varunb in forum New To Java
    Replies: 12
    Last Post: 07-09-2010, 12:50 PM
  2. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-15-2010, 11:02 PM
  3. To get time as input from user
    By yuvarani in forum New To Java
    Replies: 3
    Last Post: 12-16-2009, 12:19 PM
  4. Can't get my "if" statement to read user input
    By daletron3030 in forum New To Java
    Replies: 7
    Last Post: 01-16-2009, 05:24 AM
  5. Need help with calculating the time the user...
    By Smirre in forum New To Java
    Replies: 8
    Last Post: 11-20-2008, 01:15 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