I am new to java and to IntelliJ I've started executing some Java codes, and I am wondering why the infinite loop show more results than requested : there is the code :
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
// write your code here
char ch = 0;
for(;;){
System.out.println("Enter your character");
ch=(char)System.in.read();
System.out.println("you've entered "+ " "+ch);
if(ch =='S'){
break;
}
else{
System.out.println("Type S to Stop");
}
}
}
}
when I type A,the result was the following:
Enter your character
A
you've entered A
Type S to Stop
Enter your character
you've entered
Type S to Stop
Enter your character
I don't understand why it doesen't stop and ask for the next character,instead,it gives :
you've entered
Type S to Stop