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

Thread: another question..

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Location
    norcross, ga
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Cool another question..

    can someone take a look at the api for the String class and tell me what methods are good for doing a do- while loop to make sure the user put in more than nothing for the program to continue.
    do
        {
        System.out.println("Enter a card and its suit like this: 4S");
        card = in.nextString();
     
        }
    while (in.equals > null)
    wow that makes no sense lol but i hope you understand the "data entry check" for the program to go on.
    Last edited by helloworld922; January 27th, 2010 at 01:34 AM. Reason: Please use [code] tags!


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: another question..

    I'm going to assume that in is a Scanner object. There's no equals field/variable in the Scanner method. However, there is an equals method (very big difference). For the compiler to recognize it as a method, you must use parenthesis following the variable name (I believe white spaces are ignored).

    Secondly, Java does not support operator overloading, and by default the > operator is only defined for certain primitive data types (numbers, characters, which basically are numbers). If you want to see if that object contains something other than null, use the not or not equals method:
    while (someVar != null)

    You will also need a semi-colon after the while conditional statement because it is a do-while loop.

    The last major thing I see wrong is that you're trying to compare the Scanner object to see if it's null, not the string you read in. The scanner object should have some non-null value because it can be used to read from the stream. Further more, I'm guessing that you're reading from a user typing stuff in. This stream is never empty, but rather waits for the user to type something else in. You will need some sort of "keyword" to tell the program to stop, say quit:
    do
    {
         System.out.println("Enter a card and it's suit like this: 4S or quit to exit");
         card = in.nextString();
    } while (!"quit".equalsIgnoreCase(card));

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    etidd (January 27th, 2010)

  4. #3
    Junior Member
    Join Date
    Jan 2010
    Location
    norcross, ga
    Posts
    24
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: another question..

    okay, i seem to have gotten it... there's only one other issue with the logic of my program.