如何提示用戶循環代碼是循環否退出和錯誤輸入打印錯誤輸入並返回語句即。 「你想輸入另一個名字:」在Java中提示用戶是或否輸入
import java.util.Scanner;
public class loop {
public static void main(String[] args){
Scanner kbd = new Scanner (System.in);
String decision;
boolean yn;
while(true){
System.out.println("please enter your name");
String name = kbd.nextLine();
System.out.println("you entered the name" + name);
System.out.println("enter another name : yes or no");
decision = kbd.nextLine();
switch(decision){
case "yes":
yn = false;
break;
case "no":
yn = true;
break;
default :
System.out.println("please enter again ");
return default;
}
}
}
}
那你究竟是「循環的代碼是循環......」是什麼意思? – mok
如果用戶輸入是通過代碼從循環開始 – user3443401