String/char operators
Is there an equivalent to the "!" operator for strings and characters, to put it in context, how would I write the piece of code between the parenthesis correctly?
while("Y" != answer)
{
number=1;
}
Is there an equivalent to the "!" operator for strings and characters, to put it in context, how would I write the piece of code between the parenthesis correctly?
while("Y" != answer)
{
number=1;
}
For strings
while(!"Y".equals(answer))
for char (primitives)
while('Y' != answer)
The equals method compares the contents of the given Strings. The != compares their references
Message was edited by:
Ruly-o_O
You can write
while(!"Y".equals(answer) { //"Y" does not equal "answer"
//code here
}
Of course, answer has to be of type string.
You can also do the same with chars. Same code.
*edit*
Link for char. I assume it compares the value's of the chars and determines if they are equal from there:
http://java.sun.com/j2se/1.3/docs/api/java/lang/Character.html#equals(java.lang.Object)
Message was edited by:
lethalwire