新手问题 验证用户输入

rayoko rayoko 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
要求用户输入一个whole number 和非负数,然后验证用户输入的是否正确
下面的是例子。 谢谢。

Enter the distance in centimeters
553
553 cm = 0 miles, 6 yards, 0 feet, and 1.79 inches

Enter the distance in centimeters
-5
Exception in thread "main" java.lang.RuntimeException: Value out of range
....

Enter the distance in centimeters
2.5
Exception in thread "main" java.util.InputMismatchException
...

Enter the distance in centimeters
a
Exception in thread "main" java.util.InputMismatchException
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
rayoko
Java SE 62,621 成员 307,251 内容