如何区分整数和双精度。示例,如果我想获得整数并验证它。如果它是整数然后输出"你是正确的"别的"你错了。再试一次"。
import javax.swing.*;
public class InputExceptions {
private static int inputInt;
private static double inputDouble;
public static int inputInt() {
boolean inputOK = false;
while (inputOK == false) {
inputInt = Integer.parseInt(JOptionPane.showInputDialog("Enter Integer"));
try {
inputOK = true;
} catch (Exception e) {
JOptionPane.showMessageDialog(null,"*** ERROR: VALUE ENTERED NOT INTEGER ***");
}
} return inputInt;
}
public static void main(String[] args) {
JOptionPane.showMessageDialog(null,"*** INTEGER is correct Input: " + inputInt() + " ***");
}
}