Method:
/*** Check a string whether is numeric or not * @ Param string Str * @ return Boolean true or false */public static Boolean is_numeric (string Str) {try {double D = double. valueof (STR);} catch (Java. lang. exception e) {return false;} return true ;}
TestCode:
Public class test {/*** test the is_numeric Method * @ Param ARGs */public static void main (string [] ARGs) {string S = "123.123 "; if (is_numeric (s) {system. out. println (S + "is Numeric");} else {system. out. println (S + "not numeric");} string a = "123"; if (is_numeric (A) {system. out. println (a + "is Numeric");} else {system. out. println (a + "not numeric");} string B = "12ad"; if (is_numeric (B) {system. out. println (B + "is Numeric");} else {system. out. println (B + "not numeric ");}} /*** check a string whether is numeric or not * @ Param string Str * @ return Boolean true or false */public static Boolean is_numeric (string Str) {try {double D = double. valueof (STR);} catch (Java. lang. exception e) {return false;} return true ;}}
Test output:
123.123 is numeric123 is numeric12ad not numeric