这是产生 2 个错误的代码(我很抱歉,因为这是我第一次使用这个网站并且不完全确定如何做所有事情,但错误已在第一个错误的菜单 m 和第二个错误的 scanchoice 的 s 处标记错误)
java:22: 错误: 找不到符号choiceentry = menu();
java:52: 错误: 找不到符号choiceentry = scanchoice.nextInt();
import java.util.*;
import java.io.*;
public class Student
{
public static void main(String[] args)
{
int choiceentry;
Scanner input = new Scanner(System.in);
choiceentry = menu();
while (choiceentry != 6)
{
if(choiceentry == 1)
{
// ..do something
}
else if(choiceentry == 2)
{
//..something else
}
else if(choiceentry == 3)
{
//...something else
}
else if(choiceentry == 4)
{
// ..something else
}
else if(choiceentry == 5)
{
//..something else
}
else if(choiceentry == 6)
{
System.exit(0);
}
else
{
System.out.println("Enter \"1\", \"2\", \"3\", \"4\", \"5\" or \"6\"");
choiceentry = scanchoice.nextInt();
}
}
}
}
这是我用来设置菜单的代码,它构建得很好
import java.util.*;
import java.io.*;
public class Enroll
{
//Creation of Console Menu
public static int menu()
{
int selection;
Scanner input = new Scanner(System.in);
/***************************************************/
System.out.println("Please Select an Option:");
System.out.println("-------------------------");
System.out.println("0 - Input Course Details");
System.out.println("1 - Search");
System.out.println("2 - Add Student");
System.out.println("3 - Delete Student");
System.out.println("4 - Report (Percentage of M & F Students)");
System.out.println("5 - Save");
System.out.println("6 - Quit");
selection = input.nextInt();
return selection;
}
//End Menu
}