测试输入Java [英] Test Input Java

查看:40
本文介绍了测试输入Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我是一个相当新的java,我需要一些帮助我的第一个程序。我正在尝试制作一个程序,用户在该程序中下注他将在骰子上滚动一定数量。但是我在尝试测试我收到的输入时遇到了麻烦。我需要看看输入的赌注是否是整数,如果不是,那么他们需要租借赌注。我习惯于Visual Basic中使用的GoTo语句,但我不确定如何在java中实现这种效果。感谢帮助。

Hello, I''m fairly new to java and I need some help with my first program. I''m trying to make a program in which the user makes bet that he will roll a certain number on a die. But I am having trouble trying to test the input i receive. I need to see if the bet entered is a integer, if its not then they need to renter the bet. I am used to GoTo statements used in Visual Basic but I''m not sure how to accomplish this affect in java. Help is appreciated.

展开 | 选择 | Wrap | 行号

推荐答案

尝试将循环结构化为运行 ;循环

Try structuring your loop as a "run" loop

展开 | 选择 | Wrap | 行号


嗨!


如果你修改了什么Oralloy给你一点,你可以使用扫描仪及其 nextInt 功能。如果下一个输入不是整数,则它将通过InputMismatchException。如果您不知道如何处理例外,请 this文章应该对你有所帮助。


哦,goto是Java中的一个保留词,但由于它被认为是C / C ++中的不良实践,Java的制造者决定不它有什么用。


问候,

Nepomuk
Hi!

If you modify what Oralloy gave you slightly, you could use a Scanner and its nextInt function. If the next input is not an integer, it will through an InputMismatchException. If you don''t know how to handle Exceptions, this article should help you.

Oh, and goto is a reserved word in Java, but as it is considered bad practice in C/C++ the makers of Java decided to not have it do anything.

Greetings,
Nepomuk


好吧所以我编辑了代码来做我做的事情想要它做。我的第一组代码将在项目中进一步使用。下面的代码只能从用户那里获取输入并测试它是否为整数。

alright so I have edited the code to do what I want it to do. my first set of code was to be used farther along in the project. The code below is only supposed to get the input from the user and test if its an integer.

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


这篇关于测试输入Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆