Results 1 to 7 of 7
  1. #1
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

    Default Java string splitting and concatination

    Please help!


    Begin by asking the user to enter a date in the form of month/day/year. Store this date in a String variable.
    Next, use the appropriate String methods to swap the month and day parts of the date, and replace the slash marks with periods. Print the revised String to the screen.

    I have wrote the beginning of the program, all until it gets to where I need to split the string and then use concatenation. How do I replace the slash marks with periods, and then change it to European date form. For example an input of American date such as 03/16/1992, should be calculated to European dates such as 16.03.1992.

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

    Default Re: Java string splitting and concatination

    Why not simply put the numbers into 3 String variables and simply re-write the thing with periods and without slashes?

  3. #3
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

    Default Re: Java string splitting and concatination

    I'm not sure what you mean. The user could put in any date, and the program would have to output that in the correct form. The purpose of the program is to change the date.

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

    Default Re: Java string splitting and concatination

    What I mean is this (in pseudocode)

    Java Code:
    get date String from user
    extract month portion from date String and place in variable named month.
    extract day portion from date String and place in variable named day.
    extract year portion from date String and place in variable named year.
    re-write new date String by String concatenation (+) using the three variables above but placing a "." between the variables and of course using the variables in the correct order.
    Now it would be your job to translate this into Java.

  5. #5
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

    Default Re: Java string splitting and concatination

    I figured out how to split the variables and separate them into month, day, and year. How do replace the slash marks with periods is the problem I'm facing now.

  6. #6
    mc1234 is offline Member
    Join Date
    Sep 2011
    Posts
    24
    Rep Power
    0

    Default Re: Java string splitting and concatination

    How would I find all the slash marks in the input of the program?

  7. #7
    Join Date
    Sep 2011
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Problem splitting a string
    By sehudson in forum New To Java
    Replies: 2
    Last Post: 03-13-2011, 09:56 PM
  2. Replies: 1
    Last Post: 02-07-2011, 09:22 PM
  3. String Splitting
    By A.M.S in forum New To Java
    Replies: 1
    Last Post: 12-04-2009, 08:17 AM
  4. Splitting single string into array elements
    By phil128 in forum New To Java
    Replies: 11
    Last Post: 01-12-2009, 12:51 PM
  5. splitting string and replacing
    By itsme in forum New To Java
    Replies: 1
    Last Post: 12-11-2007, 04:08 PM

Tags for this Thread

Posting Permissions

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