import java.awt.*;
import java.awt.event.*;
publicclass GetNumber {
privatestatic Number NAN = new Double(Double.NaN);
/* Process one String, returning it as a Number subclass
* Does not require the GUI.
*/
publicstatic Number process(String s) {
if (s.matches(".*[.dDeEfF]")) {
try {
double dValue = Double.parseDouble(s);
System.out.println("It's a double: " + dValue);
returnnew Double(dValue);
} catch (NumberFormatException e) {
System.out.println("Invalid a double: " + s);
return NAN;
}
} else // did not contain . d e or f, so try as int.
try {
int iValue = Integer.parseInt(s);
System.out.println("It's an int: " + iValue);
returnnewInteger(iValue);
} catch (NumberFormatException e2) {
System.out.println("Not a number:" + s);
return NAN;
}
}
publicstaticvoid main(String[] ap) {
process("0");
process("1111111111");
}
}