0

I'm new to Java so please be kind. I thought with Dialog Boxes we almost always must use System.exit(0) so the program will close. Otherwise, the program would just keep running because JOptionPane keeps the program running. But when I ran my code with System.exit(0) I got an error. When I removed it my code ran fine. Why is that? Here is a small bit of my code.

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;



  }




 }             

}                 
Samurai
  • 189
  • 10

0 Answers0