我有一個程序,它應該顯示一個菜單從用戶選擇一個數字從菜單中選擇做它應該做的,然後返回到菜單,我不知道如何返回到菜單?如何返回程序的某些部分? java
這裏是我的代碼:
public class tst {
public static void main (String [] args){
Scanner reader = new Scanner(System.in);
System.out.println("Select");
int slct = reader.nextInt();
System.out.println("1.optionone");
System.out.println("2.optiontwo");
System.out.println("1.optionthree");
switch (slct){
case 1:System.out.println("you have selected optionone");// and then its suposed to go back to the menu
case 2:System.out.println("you have selected optiontwo");// and then its suposed to go back to the menu
case 3:System.out.println("you have selected optionthree");// and then its suposed to go back to the menu
}
}
}
問題的我怎樣才能使所以打印已選定後x選項我返回菜單一遍嗎?
謝謝它真的幫助我! –
除Java不允許使用'goto'外。像[xkcd](http://www.xkcd.com/292/)一樣可愛,在Java中使用'goto'並不錯,這是一個編譯錯誤。 – Linus