這樣應該可以
Scanner cin=new Scanner(System.in);
System.out.println("任意字符");
String s;
while (!(s=cin.next()).equals("exit")){
switch (s){
case "a":
System.out.println("gg");
break;
default:
System.out.println("輸入錯誤");
break;
}
}