Im currently creating a java program which should read the console and print it out, once again. The code looks like this:
import java.io.IOException;
public class printer {
public static void main(String[] args){
int i;
try {
while ((i = System.in.read()) != -1) {
char c = (char)i;
System.out.print(c);
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
The problem is, if you type this text below in the console you will get the first line printed, but since its a "\n"
after the word "print" the program doesn't print the second line without me pressing Enter manually
This is the text I want to print
And now I pressed Enter
And when i press enter, to get the second line, the result is:
This is the text I want to print
And now I pressed Enter
Which is not how it normally looked like.
I would prefer if the first line didn't print automatically. I want to press Enter and get both lines at the same time. Is that possible using while ((i = System.in.read()) != -1)
like I do?