Hey guys im new to java in the process of learning how would i go buy adding exceptions to my code with a try/catch when i divide by zero or enter a word instead of and integer.
package errorapp;
/**
*
* @author Brandon
*/
import javax.swing.JOptionPane;
import java.util.InputMismatchException;
public class ErrorApp {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//welcome
System.out.println("Welcome to the ErrorApp ");
String firstNumber, //first string entered by user
secondNumber; // second string entered by user
int number1, // first number to add
number2, //second number to add
quotient; //sum of number1 and number2
//read in the first number from user as a string
firstNumber =
JOptionPane.showInputDialog ( "Enter first integer" );
//read in the second number from user as a string
secondNumber =
JOptionPane.showInputDialog ( "Enter second integer" );
//convert numbers from type String to int
number1 = Integer.parseInt ( firstNumber);
number2 = Integer.parseInt ( secondNumber);
//add the numbers
quotient = number1 / number2;
//display the results
JOptionPane.showMessageDialog (null,"The answer is " + number1 + " divided by "
+ number2 + " equals " + quotient + ".", "Results",
JOptionPane.PLAIN_MESSAGE);
}
}