Java System.in issue
- by theo
`public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
if (sc.next().equals("exit")){
System.out.println("EXITING");
System.exit(0);
} else {
System.out.println("IM STILL WORKING ok?");
}
}
}
}`
So here is a piece of code i was writing the other day to try and figure sth out (doesn't really matter what). The result of executing this code is :
eIM STILL WORKING ok?
eIM STILL WORKING ok?
exit
IM STILL WORKING ok?
exit
EXITING
Can somebody kindly explain why this has happened?