ogott
27-10-2004, 23:25
hallo!
ich habe folgendes problem:
ich muss überprüfen, ob die eingabe, die an der konsole erfolgt gleich "RR" ist. wenn ich jetzt im source code folgendes eingebe, geht es natürlich:
String blume1 = "RR";
if (blume1 == "RR") {
inputError = true;
}
wenn ich allerdings folgendes eingebe, und am prompt dann "RR" eingebe, erkennt Java nicht, dass es das selbe ist:
String blume1 = EprogIO.readWord();
if (blume1 == "RR") {
inputError = true;
}
EprogIO.readWord() ist eine methode, die ich verwenden muss, damit das beispiel richtig bewertet werden kann (ist ein beispiel für die uni).
in der dokumentation steht:
public static java.lang.String readWord()
Reads characters until a whitespace character appears and returns a String.
It reads successive input-bytes, converting each input-byte separately into
a character, until it encounters a trailing whitespace character or end of
file; the characters read are then returned as a String, leading whitespace
haracters are skipped. Note that because this method processes
input-bytes, it does not support input of the full Unicode character set. A
character is considered to be a Java whitespace character if and only if it
satisfies one of the following criteria:
It is a Unicode space separator (category "Zs"), but is not a no-break space
(\u00A0 or \uFEFF).
It is a Unicode line separator (category "Zl").
It is a Unicode paragraph separator (category "Zp").
It is \u0009, HORIZONTAL TABULATION.
It is \u000A, LINE FEED.
It is \u000B, VERTICAL TABULATION.
It is \u000C, FORM FEED.
It is \u000D, CARRIAGE RETURN.
It is \u001C, FILE SEPARATOR.
It is \u001D, GROUP SEPARATOR.
It is \u001E, RECORD SEPARATOR.
It is \u001F, UNIT SEPARATOR.
If end of file is encountered before even one input-byte can be read, then
null is returned. Otherwise, each input-byte that is read is converted to
type char by zero-extension. If the character '\n' is encountered, it is
discarded and reading ceases. If the character '\r' is encountered, it is
discarded and, if the following byte converts to the character '\n', then that
is discarded also; reading then ceases. If end of file is encountered before
either of the characters '\n' and '\r' is encountered, reading ceases. Once
reading has ceased, a String is returned that contains all the characters
read and not discarded, taken in order. Note that every character in this
String will have a value less than \u0100, that is, (char)256.
Returns:
the next word from this input stream as a String.
vor und nach dem "RR" ist kein zeichen, wenn ich es nach der eingabe nochmal ausgeben lasse.
hat jemand eine idee, woran das liegen könnte?
ogott
ich habe folgendes problem:
ich muss überprüfen, ob die eingabe, die an der konsole erfolgt gleich "RR" ist. wenn ich jetzt im source code folgendes eingebe, geht es natürlich:
String blume1 = "RR";
if (blume1 == "RR") {
inputError = true;
}
wenn ich allerdings folgendes eingebe, und am prompt dann "RR" eingebe, erkennt Java nicht, dass es das selbe ist:
String blume1 = EprogIO.readWord();
if (blume1 == "RR") {
inputError = true;
}
EprogIO.readWord() ist eine methode, die ich verwenden muss, damit das beispiel richtig bewertet werden kann (ist ein beispiel für die uni).
in der dokumentation steht:
public static java.lang.String readWord()
Reads characters until a whitespace character appears and returns a String.
It reads successive input-bytes, converting each input-byte separately into
a character, until it encounters a trailing whitespace character or end of
file; the characters read are then returned as a String, leading whitespace
haracters are skipped. Note that because this method processes
input-bytes, it does not support input of the full Unicode character set. A
character is considered to be a Java whitespace character if and only if it
satisfies one of the following criteria:
It is a Unicode space separator (category "Zs"), but is not a no-break space
(\u00A0 or \uFEFF).
It is a Unicode line separator (category "Zl").
It is a Unicode paragraph separator (category "Zp").
It is \u0009, HORIZONTAL TABULATION.
It is \u000A, LINE FEED.
It is \u000B, VERTICAL TABULATION.
It is \u000C, FORM FEED.
It is \u000D, CARRIAGE RETURN.
It is \u001C, FILE SEPARATOR.
It is \u001D, GROUP SEPARATOR.
It is \u001E, RECORD SEPARATOR.
It is \u001F, UNIT SEPARATOR.
If end of file is encountered before even one input-byte can be read, then
null is returned. Otherwise, each input-byte that is read is converted to
type char by zero-extension. If the character '\n' is encountered, it is
discarded and reading ceases. If the character '\r' is encountered, it is
discarded and, if the following byte converts to the character '\n', then that
is discarded also; reading then ceases. If end of file is encountered before
either of the characters '\n' and '\r' is encountered, reading ceases. Once
reading has ceased, a String is returned that contains all the characters
read and not discarded, taken in order. Note that every character in this
String will have a value less than \u0100, that is, (char)256.
Returns:
the next word from this input stream as a String.
vor und nach dem "RR" ist kein zeichen, wenn ich es nach der eingabe nochmal ausgeben lasse.
hat jemand eine idee, woran das liegen könnte?
ogott