如何让exit返回主菜单(Java)
有人能告诉我如何让这个代码返回到主菜单时,4按下你。我知道我必须做while循环,但我不知道怎么做。现在我有退出作为返回,所以它关闭整个程序,但我希望它返回到主菜单并重新启动eventSelection如何让exit返回主菜单(Java),java,loops,do-while,Java,Loops,Do While,有人能告诉我如何让这个代码返回到主菜单时,4按下你。我知道我必须做while循环,但我不知道怎么做。现在我有退出作为返回,所以它关闭整个程序,但我希望它返回到主菜单并重新启动eventSelection import java.util.*; public class SchedulingProgram { public static void main (String [] args) { eventSelection(); } public static voi
import java.util.*;
public class SchedulingProgram
{
public static void main (String [] args)
{
eventSelection();
}
public static void eventSelection()
{
Scanner sc = new Scanner(System.in);
System.out.println("Select Scheduling Action");
System.out.print("Add and Event = 1. \nDisplay Events = 2. \nPrint Alert = 3. \nExit = 4. \nINPUT : ");
int actionSelect = sc.nextInt();
if (actionSelect >= 1 && actionSelect <= 4)
{
if (actionSelect == 1)
{
addEvent();
}
else if (actionSelect == 2)
{
displayEvent();
}
else if (actionSelect == 3)
{
printAlert();
}
else if (actionSelect == 4)
{
return;
}
}
else
{
System.out.println("Error : Choice " + actionSelect + " Does Not Exist.");
}
}
import java.util.*;
公共课排课计划
{
公共静态void main(字符串[]args)
{
事件选择();
}
公共静态void eventSelection()
{
扫描仪sc=新的扫描仪(System.in);
System.out.println(“选择调度操作”);
System.out.print(“添加和事件=1。\n显示事件=2。\n打印警报=3。\n打印警报=4。\n输入:”);
int actionSelect=sc.nextInt();
如果(actionSelect>=1&&actionSelect您可以使用这样一个无限循环来执行此操作,但用户将没有完全退出程序的选项,如果您希望命令退出程序,您可以在该命令中使用return
public static void eventSelection()
{
while (true){
Scanner sc = new Scanner(System.in);
System.out.println("Select Scheduling Action");
System.out.print("Add and Event = 1. \nDisplay Events = 2. \nPrint Alert = 3. \nExit = 4. \nINPUT : ");
int actionSelect = sc.nextInt();
if (actionSelect >= 1 && actionSelect <= 4)
{
if (actionSelect == 1)
{
addEvent();
}
else if (actionSelect == 2)
{
displayEvent();
}
else if (actionSelect == 3)
{
printAlert();
}
else if (actionSelect == 4)
{
System.out.println("Returning to selection menu");// Do nothing, next loop will be executed
}
}
else
{
System.out.println("Error : Choice " + actionSelect + " Does Not Exist.");
}
}
publicstaticvoideventselection()
{
while(true){
扫描仪sc=新的扫描仪(System.in);
System.out.println(“选择调度操作”);
System.out.print(“添加和事件=1。\n显示事件=2。\n打印警报=3。\n打印警报=4。\n输入:”);
int actionSelect=sc.nextInt();
如果(actionSelect>=1&&actionSelect从eventSelection()返回一些值。请在主函数中检查返回的值。如果它与您的值匹配,请再次调用eventSelection()那么用户将如何退出您的程序?为什么您一次又一次地问同一个问题?您刚刚问了这个问题:一小时前。上面链接中的评论已经建议了您需要做什么。为什么再次发布此内容?@user3493289您的链接指向此question@MojtabaSafaeian-更新了链接。