[英]unsure how to use method correctly
I want to take input from a scanner using .nextInt() and send it to the method below but I'm not sure how. 我想使用.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
}
int age = checkValidInput(scan);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.