好的,我是 Java 新手,但遇到了问题。当 switch 语句的某个部分完成执行时,我试图让程序从 main 重新开始。这是我的代码:
import java.util.Scanner;
public class Test{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int ans;
System.out.println("Choose an option");
System.out.print("1: To see members\n2: To add member\n3: To delete a member\n Option: ");
ans = input.nextInt();
switch(ans){
case 1:
//code to see members
break;
case 2:
//code to add members
break;
case 3:
//code to delete members
break;
default:
System.out.println("Invalid option");
}
}
}
案例一完成执行后,程序退出。如何将控制权交还给 main,以便它可以重新开始,直到用户故意退出?