Back to General discussions forum
Good afternoon. i wanted to delete 2 last symbols by: System.out.print("\b\b"); But built-in tools (java) output everything + □□. Should i delete these two characters manually in the answer line? Task 38#
Pavel, Hello!
Curious question :)
in short: yes - unwanted symbols should not be written to output
These symbols really do not work as you expect them. They are used with character terminal to move caret backwards and,
(this is optional) erase the symbol. So that at some terminal we need to output \b
, space, \b
fore erasure.
However this will almost never work with situations when output is captured by another process or written to file.
System.out
is attached to certain output stream and after we have sent something to it, we couldn't "erase" this
as if it never existed. It is the same for other languages (but behavior still may differ depending on bufferization
of stream etc).
So the system normally records carefully the whole your output and sends it back to our site. Theoretically we can extend checker so that it will try to interpret such "formatting" symbols, but this looks more like dirty hack, so I think we'd better don't.
Particularly for Task 38 I understand your motivation, but as the amount of test-cases isn't going to be large
you may better write results for each equation to String[]
and then apply String.join("; ", ...)
to it.
Thank you for your explanation.
First of all, i decided to use class stringjoiner
and StringJoiner str = New StringJoiner("; ")
, it worked on IntelliJ IDEA,
but were some errors when i tried to submit. Maybe because it appeared only in java 8
Next, i created String arrRes = new String[numOfText]
and used String.join("; ", arrRes);
. Same problem, i
It works correctly in IDEA, and there are some errors, when i use built-in tools ;)
So I decided to copy the answer from IDE. i could put the counter and when we get the last test case, then ignore the "; ", but it seems to me ugly.
Oh, thanks a lot for this hint. Really I suspect that we are still using java 7
when send solutions for execution:
public class Solution {
public static void main(String... args) {
System.out.println(System.getProperty("java.version"));
}
}
// outputs 1.7.0_80
Let me see, if this could be amended. Just a few minutes at least...
UPD: I've made a small change to call for java8
on execution API server. This should work now though one may
need to clear browser cache (or logout / login perhaps may help) for it to work properly (the word fail
may be seen
as execution result if cache retains old script).
Thanks once more for advice. I have no idea how we stuck so long with that old version (regretfully it seems no higher version is accessible).