Java Algorithm-First Digit
/*** The following static method is implemented: return the value of the first digit in the string s. ** If no number is found,-1 is returned, for example: * s = "abc24us43" 2 * s = "82445adb5" is returned, 8 * s = "AB" is returned, and the following static methods-1 ** are returned: returns the value of the first number in string s. **/Public class first digit {public static int getFirstNum (String s) {if (s = null | s. length () = 0) {return-1;} char c = s. charAt (0); if (c> = '0' & c <= '9') {return s. charAt (0)-'0'; // The value after '0' is subtracted.} return getFirstNum (s. substring (1); // the first character of the truncated String} public static void main (String [] args) {String s1 = "abc24us43 "; // returns 2 String s2 = "201745adb5"; // returns 8 String s3 = "AB"; // returns-1 System. out. println (getFirstNum (s1); System. out. println (getFirstNum (s2); System. out. println (getFirstNum (s3 ));}}