我想使用.nextInt()从扫描仪获取输入并将其发送到下面的方法,但我不确定如何。
// Method to check the user has enter an integer
static int checkValidInput ( Scanner scan)
{
while (!scan.hasNextInt()) //
{
scan.next(); // if the input is not an integer it is discarded.
System.out.println("You did not enter a integer"); // the question is asked again until the right value is entered
}
return scan.nextInt(); // the integer entered is returned to the statement that called the method
}
答案 0 :(得分:0)
int age = checkValidInput(scan);