这是我的代码,当在主菜单中输入选项时,我在尝试退出时无法退出程序。我想知道我哪里出了问题。
public static int main_menu(int a) {
System.out.println(" ###### ##### ");
System.out.println(" # # ## ##### ## # # #### ##### ##### # # # #### ");
System.out.println(" # # # # # # # # # # # # # # ## # # # ");
System.out.println(" # # # # # # # ##### # # # # # # # # # # ");
System.out.println(" # # ###### # ###### # # # ##### # # # # # # ### ");
System.out.println(" # # # # # # # # # # # # # # # # ## # # ");
System.out.println(" ###### # # # # # ##### #### # # # # # # #### \n");
System.out.println("Main Menu\n");
System.out.println("Select the Sorting method you would like to use. ");
System.out.println("(1) Bubble sort (Recommended for somewhat sorted data)");
System.out.println("(2) Selection sort (Recommended for VERY unsorted data)");
System.out.println("(3) Insertion sort (Recommened when data is nearly sorted)");
System.out.println("(4) Turtle sort (Recommened for long arrays)");
System.out.println("(5) Quit");
while(true) {
try {
a = in.nextInt();
break;
}
catch(Exception e) {
System.out.println("Invalid Input, please try again.");
in.next();
}
}
return a;
}
public static void main(String[] args) {
int menu_option = 0;
int num_values;
int unsorted_array[] = null;
main_menu(menu_option);
if (menu_option == 5) {
in.close();
return;
}
user_array(unsorted_array);
}
守着星空守着你
相关分类