while(ch == '\n' | ch == '\r');
Hi All,
I am trying to learn Java and am very new to programming/computing. I have a question. I would be much appriciated if you could answer it with very simple words.
do
{
System.out.println("Press a key following enter");
do
{
ch = (char)System.in.read();
}
while(ch == '\n' | ch == '\r');
}
while(ch!='q');
Qustion 1: I don't understand why the program ignores the carriage return and line feed generated by pressing enter and does not print out 2, 3 or mote times "Press a key following enter". As far as I understand the second loop does "read the character that is entered as long as if there is a line feed or carriage return". When you press enter they are both there and they are read as charachters.
do
{
System.out.println("Press a key following enter");
ch = (char)System.in.read();
}
while(ch!='q');
Question 2: When I use & insted | in "while(ch == '\n' | ch == '\r'); " the program behaves like in the second code example and prints out "Press a key following enter" as many as characters you entered + carriage return + line feed. Why?
Thank you





Is there anyone who could answer my question please?
I would like to know if it is a stupid question.
Thanks