Java problems for beginners (string output)
•
Java
So I'm reading the input of a file that says these lines:
NEO You're the Oracle? NEO Yeah.
So I just want to output his actual line, not what it calls Neo So I tried this:
if(line.trim()=="NEO") output=false; if (output) TextIO.putln(name + ":" + "\"" + line.trim() + "\""); // Only print the line if 'output' is true
But that didn't work It still prints Neo How can I do this?
Solution
I think you're looking for line trim(). Equals ("Neo") instead of line trim()==“NEO”
That is, you can change to get rid of the output variables
if(!line.trim().equals("NEO")) { TextIO.putln(name + ":" + "\"" + line.trim() + "\""); // Only print the if it isn't "NEO" }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码