Failed test #1 of 3. Wrong answer
This is a sample test from the problem statement!
Test input:
abc
Correct output:
cba
Your code output:
cba
Kelvin Okornoe wrote:I do not know how to avoid those spaces
. . . which looks familiar. Yes, I have seen it before. I think your two threads are so similar that I ought to merge them. Please don't ask the same question twice.Paul Clapham wrote:. . . You have this mysterious code . . .
Campbell Ritchie wrote:Kelvin Okornoe,
I have merged your topic into this topic. I hope that helps.
Campbell Ritchie wrote:
. . . which looks familiar. Yes, I have seen it before. I think your two threads are so similar that I ought to merge them. Please don't ask the same question twice.Paul Clapham wrote:. . . You have this mysterious code . . .
Don't use command/ctrl‑D (nor ctrl‑Z) on System.in. If you do, you will close the stream and cannot reopen it.
Is IDEA the same as IntelliJ (JetBrains)?
Paul Clapham wrote:
Kelvin Okornoe wrote:I do not know how to avoid those spaces
Don't put them into the array in the first place.
You have this mysterious code:
It looks to me like you think the first line is going to tell you how many characters are going to be read from that Reader. But it doesn't. Put in some debugging code and see what "reader.toString()" returns.
The fact is that you can't tell how many characters will be read from a Reader before you read them all. So using an array to receive those characters is a bad idea because you have to set up the size of the array to be the (unknown) number of characters you are going to read.
Campbell Ritchie wrote:Start by wrapping that code in a print statement.
Campbell Ritchie wrote:That doesn't solve your current problem. Just because you got a tick from an automated tester doesn't mean you have an ideal solution, or even a good solution.
I would say that an exercise using System.in.read() is going to be awkward because System.in.read() is a pain in its own right. I am going to challenge you to write that app so you get cba and you don't close System.in.
Campbell Ritchie wrote:Start by finding out how you got 31.
Campbell Ritchie wrote:And how do you think you can get System.in.read() to stop without closing System.in?
Campbell Ritchie wrote:You only get −1 if you close System.in.
Yes, there was, I think. Anybody who makes somebody use System.in.read() should be force‑fed Church tea by the gallon.Paul Clapham wrote:. . . some business . . . about pressing a control character . . . to [close System.in]
Which is one possible solution to my little challenge.. . . "Take all input until the user presses Enter . . ."
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|