Java 如何重新启动开关菜单?
我有一个Java 如何重新启动开关菜单?,java,Java,我有一个开关菜单,我想在完成案例后重新启动该菜单。我知道它是通过While循环完成的,但问题是它是从案例1开始的 这是我的文件界面,它有开关菜单: out.println("Choose an option:"); out.println("1. Array of guests"); out.println("2. Array of hosts");`` while(exit == false) { // Calls functions
开关
菜单,我想在完成案例
后重新启动该菜单。我知道它是通过While
循环完成的,但问题是它是从案例1
开始的
这是我的文件界面,它有开关
菜单:
out.println("Choose an option:");
out.println("1. Array of guests");
out.println("2. Array of hosts");``
while(exit == false) {
// Calls functions defined in CL
switch(menu){
``
case 1:
CL.guests = new String [CL.define_size()];
CL.fill_array(CL.guests);
break;
case 2:
CL.hosts = new String [CL.define_size()];
CL.fill_array(CL.hosts);
break;
}
这是我的CL文件,它具有以下功能
public class CL {
public static BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
public static PrintStream out = System.out;
static String [] guests;
static String [] hosts;
//Los arreglos se definen con un método
public static int define_size () throws IOException {
out.println("Enter the size of the array");
int number = Integer.parseInt(in.readLine());
return number;
}
public static void fill_array (String parray []) throws IOException{
for(int i = 0; i < parray.length; i++){
out.println("Enter the value of " + (i+1) );
parray[i] = in.readLine();
}
}
public static void print_array(String [] parray){
for(int i = 0; i < parray.length; i++){
out.println(parray[i]);
}
}
在您提供的代码中,您没有读取
菜单
的值,因此菜单
始终设置为相同的值。另外,您在while循环之外打印菜单,因此它只会打印一次菜单。无关:不要执行“someBoolean==true”(或false)。例如,在(!exit)时只需转到。或者把它转过来,以避免否定:while(continueLoop)
Choose an option::
1. Register guests
2. Register hosts
//Menu
1
Enter the size of the array
2
Enter the name of value 1
guest1
Enter the size of the array // why does it loop to case 1 instead of menu?