请问怎么判断在控制台输出的数值,是不是数字?

Sey_1 2019-04-15 06:58:19
num= num1= 定义num,num1为赋值输出,在if选择结构中该如何表示哪?求解
...全文
246 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Sey_1 2019-04-26
  • 打赏
  • 举报
回复
引用 1 楼 qq_44795913的回复:
数字,nextint,如果不是,不是会抛输入数据类型不符异常?,判断是否为0到9这一区间
是的是的谢谢大佬
Sey_1 2019-04-26
  • 打赏
  • 举报
回复
引用 2 楼 益达达达达达达达达达达的回复:
//正则表达式数字验证
public boolean isNumber(String str)
{
java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]*");
java.util.regex.Matcher match=pattern.matcher(str);
return match.matches();
}

"^\\d+$"  //非负整数(正整数 + 0)
"^[0-9]*[1-9][0-9]*$"  //正整数
"^((-\\d+)|(0+))$"  //非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$"  //负整数
"^-?\\d+$"    //整数
"^\\d+(\\.\\d+)?$"  //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"  //正浮点数
"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"  //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"  //负浮点数
"^(-?\\d+)(\\.\\d+)?$"  //浮点数

https://blog.csdn.net/thl331860203/article/details/6086674?utm_source=blogxgwz8
https://www.cnblogs.com/haobadea/p/5987938.html
嗯嗯谢谢大佬,赐教
  • 打赏
  • 举报
回复
//正则表达式数字验证
public boolean isNumber(String str)
{
java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]*");
java.util.regex.Matcher match=pattern.matcher(str);
return match.matches();
}

"^\\d+$"  //非负整数(正整数 + 0)
"^[0-9]*[1-9][0-9]*$"  //正整数
"^((-\\d+)|(0+))$"  //非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$"  //负整数
"^-?\\d+$"    //整数
"^\\d+(\\.\\d+)?$"  //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"  //正浮点数
"^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"  //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"  //负浮点数
"^(-?\\d+)(\\.\\d+)?$"  //浮点数

https://blog.csdn.net/thl331860203/article/details/6086674?utm_source=blogxgwz8
https://www.cnblogs.com/haobadea/p/5987938.html
巴顿.com 2019-04-15
  • 打赏
  • 举报
回复
数字,nextint,如果不是,不是会抛输入数据类型不符异常?,判断是否为0到9这一区间

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧