Java System.in issue
Posted
by
theo
on Stack Overflow
See other posts from Stack Overflow
or by theo
Published on 2011-01-16T01:49:46Z
Indexed on
2011/01/16
1:53 UTC
Read the original article
Hit count: 476
java
`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?
© Stack Overflow or respective owner