I am trying to create a basic calculator program and I want to remove all non-numerical characters from the string input. (I am a java newbie). This is my current code:
package calculator;
import javax.swing.JOptionPane;
public class sub {
public static void main(String[] args) {
//Text & Input Box #1
String input = JOptionPane.showInputDialog(null,
"Input the first number",
"Subtraction",
JOptionPane.QUESTION_MESSAGE);
//Input Box #2
String input1 = JOptionPane.showInputDialog(null,
"Input the second number",
"Subtraction",
JOptionPane.QUESTION_MESSAGE);
//Data Collection
int data1 = Integer.parseInt(input);
int data2 = Integer.parseInt(input1);
//Data Sum
int sum = data1 - data2;
//Output
JOptionPane.showMessageDialog(null, sum, "The Answer",
JOptionPane.INFORMATION_MESSAGE);
}
}