zoukankan      html  css  js  c++  java
  • java实现数字的值返回

    以下的静态方法实现了:把串 s 中第一个出现的数字的值返回。
    如果找不到数字,返回-1
    例如:
    s = “abc24us43” 则返回 2
    s = “82445adb5” 则返回 8
    s = “ab” 则返回-1

    /*
    
    */
    public class Demo09_FirstNum {
    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.substring(1)); //填空
    }
    public static void main(String[] args){
    String s = "abc24us43";
    System.out.println(getFirstNum(s));
    }
    }
    
    

    运行结果:
    2

  • 相关阅读:
    线段树(已修改+补题
    畅通工程
    线段树
    charles
    flash
    mysql node pool
    node简单操作mysql的类
    小于任意数字的随机数
    文件系统的移植
    驱动
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076851.html
Copyright © 2011-2022 走看看