Java 整数、双精度或字符串的try/exception
如何区分整数和双精度。例如,如果我想得到整数并验证它。如果是整数,则输出正确,否则输入错误。再试一次Java 整数、双精度或字符串的try/exception,java,string,integer,double,Java,String,Integer,Double,如何区分整数和双精度。例如,如果我想得到整数并验证它。如果是整数,则输出正确,否则输入错误。再试一次 import javax.swing.*; public class InputExceptions { private static int inputInt; private static double inputDouble; public static int inputInt() { boolean inputOK = false;
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() + " ***");
}
}
您是否尝试过将InputT=Integer.parseIntJOptionPane.showInputDialogEnter Integer;在试块里面?是的,我现在拿到了。谢谢你,伙计。。。。。