用 java.util.Scanner 如下
public static void main(String[] args) {
while(true){
Scanner scan = new Scanner(System.in);
System.out.println("请输入:");
String str = scan.next();
if(!"q".equals(str)){
System.out.println("输入:"+str);
}else {
break;
}
}
}
https://zhidao.baidu.com/question/339642195.html