我有一個程序,玩超級英雄的頂級王牌遊戲,我需要重複每次用戶玩遊戲時的菜單。我試圖創建一個方法(displayMenus),它將被插入到每個switch語句中(關閉程序除外),但是我不明白如何讓它返回這個菜單。如何獲得system.out.println返回方法
public class Heros {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int index = 0;
do {
int inp = input.nextInt();
switch (inp) {
//FIRST
case 1:
index = 0;
System.out.println(HerosAsList.getHeros().get(index));
System.out.println(displayMenus);
break;
//NEXT
case 2:
index++;
if (index > HerosAsList.getHeros().size() - 1) {
index = HerosAsList.getHeros().size() - 1;
}
System.out.println(HerosAsList.getHeros().get(index));
System.out.println(displayMenus);
break;
//PREV
case 3:
index--;
if (index < 0) {
index = 0;
}
System.out.println(HerosAsList.getHeros().get(index));
System.out.println(displayMenus);
break;
//LAST
case 4:
index = HerosAsList.getHeros().size() - 1;
System.out.println(HerosAsList.getHeros().get(index));
System.out.println(displayMenus);
break;
//QUIT
case 0:
System.out.println("Closing system");
System.exit(inp);
break;
}
}
while(index<HerosAsList.getHeros().size());
}
public static displayMenus() {
System.out.println("First - 1");
System.out.println("Next - 2");
System.out.println("Prev - 3");
System.out.println("Last - 4");
System.out.println("Quit - 5");
System.out.println("");
System.out.println("Enter Choice:");
}
}
任何幫助是極大的讚賞,我似乎無法讓我的身邊方法的頭!