Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need help with formatting output - PLEASE HELP :(

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Need help with formatting output - PLEASE HELP :(

    Basically all I'm after is to be able to format a String that is inputted by the user:

    For example:

    My code would look something like this:
    public class TestData {
    public static void main(String[] args) {
    Scanner kbd = new Scanner(System.in);
     
    System.out.println("Please enter your name: ")
    String name = kbd.nextLine();
     
    }
     
    }

    I want to format the user input to something like this:

    USER ENTERS John Smith
    OUTPUT: J Smith

    USER ENTERS: John Paul Smith
    OUTPUT: J Smith

    USER ENTERS John Paul-Smith
    OUTPUT: J Smith

    How would I go about doing this?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Need help with formatting output - PLEASE HELP :(

    Read the full name, split out out parts of the name, get the first letter of the first name, print it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with formatting output - PLEASE HELP :(

    [QUOTE=ProgrammablePeter;132275]Basically all I'm after is to be able to format a String that is inputted by the user:

    For example:

    My code would look something like this:
    *** code removed
    Last edited by Norm; December 2nd, 2013 at 09:58 AM. Reason: Please do NOT do the OPs work

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Need help with formatting output - PLEASE HELP :(

    @racoonic
    Please read this: The Problem with Spoon-feeding
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Formatting my output
    By chemical_dog in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 7th, 2013, 07:24 PM
  2. Formatting 2d Array Output
    By dspear in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: December 14th, 2011, 06:45 PM
  3. Formatting Output
    By mael331 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: September 14th, 2011, 07:41 PM
  4. Formatting output of a Double
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 11th, 2010, 05:20 PM
  5. Replies: 3
    Last Post: August 19th, 2009, 12:30 PM