首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请问关于Scanner的有关问题

2012-10-19 
请教关于Scanner的问题Java codeScanner s new Scanner(System.in)String userInputwhile(s.hasNext()

请教关于Scanner的问题

Java code
Scanner s = new Scanner(System.in);String userInput;while(s.hasNext()) {    userInput = s.next();    out.println(userInput);    System.out.println(br1.readLine());    if(userInput == "End") {        break;    }}


请问这while为什么终止了还是运行不了下一行程序呢?即使输入End,跳出循环还是一样。程序一直在while卡着不动了。
还有就是,运行了Scanner以后,程序是否会一直等待输入,然后有一个输入后就自动关闭Scanner呢?

[解决办法]
userInput == "End"改为userInput .equals("End")

热点排行