【发布时间】:2020-12-07 17:35:47
【问题描述】:
我的主要方法是使用 switch case 菜单,效果很好。如果用户选择 2,它会转到该类并正常返回,但如果用户选择 1,它会执行该方法,然后停止并且不返回。我错过了什么?如果我执行系统退出,它会退出,但我需要它返回菜单。
停止的方法结束:
for (int index = 0; index < items.length; index++) {
System.setOut(console);
System.out.printf("%-16s %16d %16d %16d %16s \n", items[index], supplyOnHand[index], last24HourUsage[index], daysOnHand[index], status[index]);
System.setOut(o);
System.out.printf("%-16s %16d %16d %16d %16s \n", items[index], supplyOnHand[index], last24HourUsage[index], daysOnHand[index], status[index]);
}
}
}
主要:
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
boolean exit = false;
do {
System.out.println("Please enter your choice:");
System.out.println("1. Enter new data.");
System.out.println("2. Review latest data.");
System.out.println("3. Exit.");
Scanner sc1 = new Scanner(System.in);
int choice = sc1.nextInt();
switch (choice){
case 1:
Dashboard.main();
break;
case 2:
ReadFile.main();
break;
case 3:
exit = true;
break;
}
} while (!exit);
}
}
编辑希望使它更清晰。我不擅长措辞。 如果我选择 2 它会执行并返回菜单:
Please enter your choice:
1. Enter new data.
2. Review latest data.
3. Exit.
2
Please enter your choice:
1. Enter new data.
2. Review latest data.
3. Exit.
如果我选择 1,它不会返回,只是挂起:
Please enter your choice:
1. Enter new data.
2. Review latest data.
3. Exit.
1
Welcome to the Rationed Medical Supply Dashboard.
After your entries of stock on hand and daily usage,
your days on hand and supply status will be displayed for each item.
The results will be displayed in the log below and
also in a running log in the file DashboardLog.txt
_______________________________________________________________________________________________________________________
How many items are we tracking today?
1
Enter name of item # 1:
1
How many of item # 1 do we have?:
1
What was the usage of item # 1 in the last 24 hours:
1
12/07/20 12:47:37
Current status of all items being tracked:
Item| Supply on hand| Last 24 Hr Usage| Days on hand| Status|
-------------------------------------------------------------------------------------
1 1 1 1 Critical
【问题讨论】:
-
“正常返回”和“不返回”是什么意思?执行过程中有没有异常?
-
已编辑以使其更清晰。