Adding in CS-115 coursework

This commit is contained in:
Frank
2025-09-27 14:53:33 -06:00
parent ad3eff2688
commit 7df7f7f319
22 changed files with 708 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import javax.swing.*;
import java.util.InputMismatchException;
public class ExceptionsDemo {
public static void main(String[] args) {
int numerator = 0;
int denominator = 0;
int result;
String inputString;
try {
inputString = JOptionPane.showInputDialog(null, "Enter a number to be divided");
numerator = Integer.parseInt(inputString);
inputString = JOptionPane.showInputDialog(null, "Enter a number to divide into the first number");
denominator = Integer.parseInt(inputString);
result = numerator / denominator;
JOptionPane.showMessageDialog(null, numerator + " / " + denominator + "\nResult is " + result);
} catch (ArithmeticException exception) {
JOptionPane.showMessageDialog(null, exception.getMessage());
result = 0;
} catch (NumberFormatException exception) {
JOptionPane.showMessageDialog(null, "Please enter only Integers!");
result = 0;
}
}
}