- /*
- *
- 以下的静态方法实现了:把串s中第一个出现的数字的值返回。
- 如果找不到数字,返回-1
- 例如:
- s = "abc24us43" 则返回2
- s = "82445adb5" 则返回8
- s = "ab" 则返回-1
- */
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class test3 {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(System.in));
- String string=bufferedReader.readLine();
- System.out.print(getFirstNum(string));
- }
- 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 Integer.valueOf(""+c);
- }
- return getFirstNum(s.substring(1));
- //return 0;
- }
- }