我正在嘗試編寫一個程序,讓您在兩件事情中進行選擇。 但是在執行我選擇的選項後,我希望能夠返回相同選項的開頭。Switch或If語句
switch (option) {
case 1:
System.out.println("Start of option 1");
//option 1 will do things here
System.out.println("End of option 1");
//I want to return at the beginning of this case at the end of it
break;
case 2:
System.out.println("Start of option 2");
//option 2 will do things here
System.out.println("End of option 2");
//I want to return at the beginning of this case at the end of it
break;
default:
break;
}
也可以選擇退出所選案例。 另外,用if語句來實現我想要做的事情會更容易嗎?
只要使用方法在任何開關或如果和循環在那裏。 – Tom
聽起來像你需要一個循環 –