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 9 of 9

Thread: Java help

  1. #1
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Java help

    hey, i need to write a method that can uses the scanner to get a string (using the next() method), the string must then be changed to capital letter. i've gotta print the converted one so it says " hello ". i've been told to carrion the string until it closes to once the last message has been printed like "last". the program should close if i enter strings like CLOSE, CloSe, close ectect

    unsure how to do it


    import java.util.Scanner;
    public class London {


    static void readWords()

    String b = "Hello";

    Scanner scanner = new Scanner(b);
    b.toUpperCase();

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java help

    There are plenty of code examples here on the forum. Do a Search.
    Also there are examples in the API doc for the Scanner class:
    Java Platform SE 7
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    Hey,

    Thanks for replying. I'm not exactly sure about what i should be searching for, cause as mentioned i'm unsure about the approach im supposed to take...so not too sure about what to mention in the search.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java help

    i need to write a method that can uses the scanner
    I thought you wanted to know how to use the Scanner class. If so look for "Scanner"
    Did you look at the API doc?

    If that isn't a problem, can you explain what your problem is?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    I don't know how to get the program to close when someone types close, Close,CloSe,CLoSE ectect in all capitalized forms

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java help

    how to get the program to close
    One way to have a program to close is to call the System.exit(0) method.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Java help

    b.toUpperCase();
    Remember that Strings are immutable (they cannot be changed). Most of the methods in the String class return a new String which you need to save somewhere.

    As to how to handle if user enters "close" use the equalsIgnoreCase method in an if statement.
    Improving the world one idiot at a time!

  8. #8
    Member
    Join Date
    Nov 2013
    Posts
    51
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Java help

    So i cannot use b.toUpperCase(); ?

  9. #9
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Java help

    That is not what I said. Read my post again.
    Improving the world one idiot at a time!