华为OJ--有效数字

来源:互联网 发布:电脑玩手游用什么软件 编辑:程序博客网 时间:2024/04/28 17:45
/**
 * @param String s 输入字符串
 * 
 * @description: 
 *     判断字符串是否是有效数字,是返回0,不是返回-1
 *    
 * @example:
 *     123.456 是有效数字,返回0
 *     123a 不是有效数字,返回-1

 */


Demo.java

<pre name="code" class="java">public class Demo{public int NumType(String s){try {Double d = Double.valueOf(s);return 0;} catch (Exception e) {// TODO: handle exceptionreturn -1;}}}




0 0