how to get the final output without pressing enter?

Solution 1:

Its not the fault of the IDE. It is how it deals with copy-pasting text into the console.

The text is handed over to the Java code as you paste it, line by line. Input is only handed over once you finish the line. The previous lines are all terminated already with a newline symbol but the last line is not.

So you have to either add a newline to the end of your copy-pasta or hit enter to produce one yourself. So before you terminate the last line, the last line is never handed over to Java but is still only in the console.

For example, if you copy pasta this instead:

4
101
1111
00110
111111

(note the last, empty line)

it will work as expected, since you finished the 111111 line, i.e. it is 111111\n and not just 111111.