为什么我的代码中不需要System.exit(0)?

时间:2019-02-13 05:32:36

标签: java

我是Java的新手,所以请保持友好。我认为使用“对话框”时,我们几乎总是必须使用System.exit(0),这样程序才能关闭。否则,该程序将一直保持运行状态,因为JOptionPane使该程序保持运行状态。但是,当我使用System.exit(0)运行代码时,出现错误。当我删除它时,我的代码运行良好。这是为什么?这是我的一小段代码。

import javax.swing.JOptionPane;
import java.util.Scanner;

public class Myprogram              
{              


   //This code is for Programming Challenge 3.1 "Roman Numerals"            


 public static void main(String[] args)              
 {              
  String userInput;
  int parsedInput;

  //Pops up message box asking user for input.
  userInput = JOptionPane.showInputDialog("Please enter a whole number in the range of 1 though 10.");
  parsedInput = Integer.parseInt(userInput); //converts string to a int value.


  //A switch statment which gives user the type of roman numberal for the number they entered which is in the range of 1-10.
  switch (parsedInput)
  {
     case 1:
        JOptionPane.showMessageDialog(null, "The number you entered converted to the Roman numeric system is: I ");
        break;

     case 2:  
        JOptionPane.showMessageDialog(null, "The number you entered converted to the Roman numeric system is: II ");
        break;


     default:
        JOptionPane.showMessageDialog(null, "You entered a invalid type of input.");
        break;



  }




 }             

}                 

0 个答案:

没有答案