
-----------------------------------
Justin_
Wed Mar 01, 2006 7:38 pm

is c++'s != the same in java?
-----------------------------------

import java.util.*;
import java.io.*;
public class NumberGuess3 
{
    public static void main(String

can someone tell me why it doesnt go back to the loop after try again?  I know it wont try the whole thing again due to the breadth of the while loop, but it should do the while loop again.  Unless the != (does not equal) sign is different in java.

-----------------------------------
wtd
Wed Mar 01, 2006 8:12 pm


-----------------------------------
Java's == and != operators work the way you'd expect... for "native" types.  For object types they act referentially.

someString == someString2

Only is true if they're actually the same object.  If you wish to test for structural equality, use the equals method.

-----------------------------------
Andy
Wed Mar 01, 2006 8:35 pm


-----------------------------------
in c++ != and == will return u 0 or 1, in java, true != 1 and false != 0

-----------------------------------
Justin_
Wed Mar 01, 2006 9:32 pm


-----------------------------------
I'm begining to suspect that the readLine() method does something funky.  

observe:  

playAgain = input.readLine();

while (playAgain == "yes")
{
  execute this
}

okay, so if i type in "yes" without quotes, it should do the while loop right?

-----------------------------------
Justin_
Wed Mar 01, 2006 9:37 pm


-----------------------------------
Please tell me why it doesnt repeat itself if you type: yes after you guessed the number correct.


import java.util.*;
import java.io.*;
public class NumberGuess3 
{
  public static void main(String

-----------------------------------
Andy
Wed Mar 01, 2006 9:54 pm


-----------------------------------
two suggestions, check if the string you're comparing with "yes" is indeed just "yes" and no endline character, output the length of the string, and check each character. Also, make sure you're using Java 1.50 if you're going to do that, if not you'll have to use string.equals

-----------------------------------
wtd
Wed Mar 01, 2006 10:17 pm


-----------------------------------
I've given you the answer.

If you wish to strip off any extra spaces (newline or otherwise), use the trim method.

-----------------------------------
Justin_
Wed Mar 01, 2006 10:39 pm


-----------------------------------
I output the length of the word yes and it returns 3.  Also I read that the readLine() method does not include the terminating characters or anything like that when writing to a string variable.  

wtd, if you've given the answer then I don't understand it.  A trim method will not help in this situation considering the string is just "yes"  so there has to be something else wrong with my program.  

Whoever can tell me what earns a cookie :D

-----------------------------------
wtd
Wed Mar 01, 2006 11:25 pm


-----------------------------------
Strings are objects in Java.  There's your answer.

-----------------------------------
Justin_
Wed Mar 01, 2006 11:32 pm


-----------------------------------
oh indeed, thanks so much.  When you say equals method I tried the statement with one equal sign lol.  But now I understand, thanks.

-----------------------------------
[Gandalf]
Thu Mar 02, 2006 11:28 pm


-----------------------------------
hi
Eh?  Would I be correct in the assumption that someone has commandeered your account?
