Determine if a string is numeric: Difference between revisions

Content added Content deleted
m (→‎[[Java]]: made a function)
Line 44: Line 44:
[[Category:Java]]
[[Category:Java]]


public boolean isNumeric(String input) {
String s = "123";
try {
try {
int i = Integer.parseInt(s);
Integer.parseInt(input);
// use i
return true;
}
}
catch (Exception e) {
catch (Exception e) {
// s is not numeric
// s is not numeric
return false;
}
}
}