我有一切正常但System.exit(0)
。如果按下按钮,它应该在任何剩余时间退出。我不知道该怎么做。非常感谢帮助。
/*
Creates the perfect hard-boiled(simulates 12 minutes in boiling water) or soft-boiled
egg(simulates 6 minutes in boiling water). Both options require 10 seconds of rinsing
under cold water after necessary time for boiling. Allow user to exit any remaining
time.
*/
import java.io.*;
import java.util.*;
public class AdvancedEggMaker {
public static void main(String[] args) {
MCU mcu = null;
try {
mcu = new MCU(new Communicator(args[0]));
}
catch (IOException e) {
System.out.println(e);
}
mcu.println("SW2 - HB Egg", 0);
mcu.println("SW3 - SB Egg", 1);
while (true) {
int sw = mcu.getSwitch();
if (sw == 2) {
mcu.println("Hard Boiled Egg", 0);
mcu.println("Place Egg in", 0);
mcu.println("boiling water", 1);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw2 = mcu.getSwitch();
switch (sw2) {
case 4:
int t = 720;
while (t > 0 && sw2 == 4) {
t = (t - 1);
mcu.println("Boiling...", 0);
mcu.println((t / 60) + "mins left...", 1);
}
break;
case 5:
System.exit(0);
break;
}
}
if (sw == 3) {
mcu.println("Soft Boiled Egg", 0);
mcu.println("Place Egg in", 0);
mcu.println("boiling water", 1);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw2 = mcu.getSwitch();
switch (sw2) {
case 4:
int t = 360;
while (t > 0 && sw2 == 4) {
t = (t - 1);
mcu.println("Boiling...", 0);
mcu.println((t / 60) + "mins left...", 1);
}
break;
case 5:
System.exit(0);
break;
}
}
mcu.println("Rinse Egg", 0);
mcu.println("then press SW4", 0);
mcu.println("SW5 - Quit", 1);
int sw3 = mcu.getSwitch();
if (sw3 == 4) {
double t = 10;
while (t > 0.0) {
t = (t - 1);
mcu.println("Rinsing...", 0);
mcu.println(t + "Secs left...", 1);
}
if (sw == 5) {
System.exit(0);
}
}
}
}
}
答案 0 :(得分:0)
您确定执行是否已到达您的System.exit(0)语句之一。我没有看到任何sysout或日志来帮助您确定。首先要检查一下,因为我认为没有任何理由不起作用。
其次,您可以检查代码中是否有一些后台线程。可能是您可能在某个线程中的某个位置打开一些连接/流并且不让System.exit(0)终止该进程。