[leetcode]Valid Number
2015-09-22 18:53
405 查看
问题叙述性说明:
Validate if a given string is numeric.
Some examples:
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
考虑:93.3f, 23.43D 。 2341234L等数字均为无效数字,数字中包括的字母仅仅能是e
代码:
Validate if a given string is numeric.
Some examples:
"0"=>
true
" 0.1 "=>
true
"abc"=>
false
"1 a"=>
false
"2e10"=>
true
Note: It is intended for the problem statement to be ambiguous. You should gather all requirements up front before implementing one.
考虑:93.3f, 23.43D 。 2341234L等数字均为无效数字,数字中包括的字母仅仅能是e
代码:
public class Valid_Number { //java public boolean isNumber(String s) { if(s == null || s.trim().isEmpty()) return false; s = s.trim().toLowerCase(); char ch = s.charAt(s.length()-1); if(ch =='f' || ch =='l' || ch =='d') return false; try{ Double.valueOf(s); return true; }catch(Exception e){ return false; } } }
相关文章推荐
- 第四周 建立单链表
- 自定义View,ViewGroup,SurfaceView
- mysql-5.6.25 配置和安装
- iOS超精细详解之GCD
- poj 2208
- C++学习记录之vector容器
- Android中的几个onTouch()事件、onKeyDown监听返回键无效
- java的构造函数
- Nginx和Apache的区别
- 线程同步
- 测试基础知识总结
- 第二次作业——结对项目之需求分析与原型模型设计
- 第二次作业
- Reference VS Pointer
- Stub方式接口化封装axis2 webservice:实现衍生对象与原始对象的相互转换
- WebSphere 7.0 ND 缺省端口号
- C++ 长整型数据的输出
- 1280:前m大的数
- 第二次作业
- webapp开发——jqmobi框架的快速使用