java—我的一个类在完成后不会返回到主类我怎样才能让它回来?

ygya80vv  于 2021-07-03  发布在  Java
关注(0)|答案(2)|浏览(325)

我的主要方法是开关盒菜单,这是工作良好。如果用户选择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
oyjwcjzk

oyjwcjzk1#

我的一个类在完成后没有返回到主类。我怎样才能让它回来?
java不是这样工作的。
方法运行。方法返回。类只是一袋袋属性;一些字段,一些方法。他们不跑。他们不会回来。
你把系统搞砸了,然后问“拖延”。那是个糟糕的计划,别搞砸了。
它一点也不拖延,至少,你的浆糊里没有任何东西表明这一点。然而,你正在 System.out 所以,最有可能的情况是,您的代码没有延迟,而是。 System.out.println("Please enter your choice:"); 被送到你看不见的地方。 System.setOut 变化 System.out 到处都是。

ugmeyewa

ugmeyewa2#

我想出来了。我只想结束于:

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]);

现在很好用。谢谢你的帮助!

相关问题