蓝桥-第一个数字

来源:互联网 发布:视频剪辑电脑软件 编辑:程序博客网 时间:2024/05/06 23:27


以下的静态方法实现了:把串s中第一个出现的数字的值返回。
如果找不到数字,返回-1


例如:
s = "abc24us43"  则返回2
s = "82445adb5"  则返回8
s = "ab"   则返回-1   


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 _____________;  //填空

return ___________________;  //填空
}






请分析代码逻辑,并推测划线处的代码。


答案写在 “解答.txt” 文件中


注意:只写划线处应该填的内容,划线前后的内容不要抄写。




public class Test {   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 c-'0' ;  //填空return getFirstNum(s.replaceFirst("^\\w", ""));  //填空}    //start 提示:自动阅卷起始唯一标识,请勿删除或增加。     public static void main(String args[])     {         int[] q=new int[10];    System.out.print(new Test().getFirstNum("afag3af"));    }     //end //提示:自动阅卷结束唯一标识,请勿删除或增加。}