public class Main {
public static void main(String[] args) {
int count = 0;
Scanner s = new Scanner(System.in);
System.out.println("请输入字符串:");
String str;
while (s.hasNext()) {//判断键盘是否还有输入
str = s.next();//注意区分next()和nextLine()区别!!!
if (str.equals("w")) {//注意里面的是双引号"w",单引号'w'识别不出导致出错
break;
} else {
count++;
System.out.println(str);
}
}
System.out.println("共输入" + count + "行");
}
}



