Java String Problems

Discussion in 'General Computer Support' started by rbnbenjamin, Feb 3, 2009.

  1. rbnbenjamin

    rbnbenjamin

    Joined:
    Feb 3, 2009
    Messages:
    1
    Can anyone help me? I am a beginning Java programmer, and I can't figure out how to do the following.:


    Write a program names L5GetName where the user enters a String. The string contains the users first name and last name separated by one of more spaces. Output the name as last name, first name. Capitalize the first letter of each name. The following is sample output that you can use to test your program. Note the case that should detect an error.

    Input Output
    john doe Doe, John
    mary Lamb Lamb, Mary
    bob Error: must have first and last name
    BOB HOPE Hope, Bob
    mary lamb Lamb, Mary

    Note: Your program should be in a loop so that when the user clicks cancel, the program exits. It exits the loop when IO.inputString() returns a null.
    Note: Make sure to include your name, date, purpose of the program, and the name of the source file as comments at the top.
    Hint: For this lab, use of the following string methods is sufficient: equals, substring, indexOf, length, toUpperCase, toLowerCase, trim and string concatenation.


    Write a program named L5GetString that accepts a string and outputs:

    a. The string
    b. Count the number of vowels in the string
    c. The offset to the first occurrence of a vowel
    d. A string that replaces all occurrences of the first letter of the input string by the second letter of that string.


    Note: Like the previous example, exit the program when the user clicks cancel while entering the string. Include your name, date, and name of the source file as comments at the top.
    Hint: For this lab, use of the following string methods is sufficient: charAt, indexOf, length.

    Sample input and output

    The string is abracadabra
    Count of vowels is 5
    Index of first vowels is 0
    The replacement string is bbrbcbdbbrb

    The string is sississippi
    Count of vowels is 4
    Index of first vowels is 1
    The replacement string is iiiiiiiippi



    Thanks,

    Bobby
    rbnbenjamin, Feb 3, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fernando Kohan

    JAVA VIRTUAL MUCHINE OR SUN JAVA

    Fernando Kohan, Nov 13, 2004, in forum: Firefox
    Replies:
    1
    Views:
    768
    Clark
    Nov 14, 2004
  2. dakine

    MS Java or Sun Java???

    dakine, Jul 20, 2004, in forum: Computer Support
    Replies:
    9
    Views:
    1,446
  3. newasp.net
    Replies:
    1
    Views:
    1,580
    imransyed63
    Aug 21, 2008
  4. freezea
    Replies:
    0
    Views:
    2,019
    freezea
    Oct 8, 2009
  5. gcatlin

    Java string replace

    gcatlin, Jun 28, 2010, in forum: Software
    Replies:
    0
    Views:
    2,528
    gcatlin
    Jun 28, 2010
Loading...

Share This Page