如何在Java中终止程序

  • 本文关键字:终止程序 Java java
  • 更新时间 :
  • 英文 :


这是我的代码。程序不会给我最后一行"感谢您使用基本用户界面程序"。

public class nameClass {
  public static void main(String[] args) {
    String input;
    String name;
    int age;
    double mileage;
    displayApplicationInformation();
    displayDivider("Start Program");
    TerminateApplication();
    // process name
    displayDivider("Get Name");
    name = getInput("name");
    System.out.println("Your name is: " + name);
    // Process age
    displayDivider("Get Age");
    input = getInput("Your age");
    age = Integer.parseInt(input);
    System.out.println("Your age is: " + age);
    // Process Mileage
    displayDivider("Get Mileage");
    input = getInput("Your MPG");
    mileage = Double.parseDouble(input);
    System.out.println("Your car MPG is: " + mileage);
  }// end of main
  public static void displayApplicationInformation()
  {
    System.out.println("Welcome to the Basic User Interface Program");
  }// end of displayApplicaionInformation
  public static void displayDivider(String outputTitle) {
    System.out.println("*********" + outputTitle + "********");
  }// end of displayDvider
  public static String getInput(String inputType)
  {
    String input = "";
    input = JOptionPane.showInputDialog("Enter the " + inputType);
    return input;
  }
  public static void TerminateApplication()
  {
    System.out.println("Thank you for using the Basic User Interface program");
    return;
  }
}// end of MainClass

您必须实际调用方法TerminateApplication;

System.out.println("Your car MPG is: " + mileage);
TerminateApplication();

简单,调用TerminateApplication
你在main()的第9行做。
这里,看看这个:

displayDivider("Get Mileage");
input = getInput("Your MPG");
mileage = Double.parseDouble(input);
System.out.println("Your car MPG is: " + mileage);
//add this...
TerminateApplication();

希望这对你有帮助!

最新更新