【发布时间】:2016-05-26 19:01:27
【问题描述】:
我希望用户只能在控制台中输入不超过三个数字。有什么方法可以限制或阻止控制台接受键盘输入?
谢谢
import java.util.Scanner;
public class Numbers {
public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.print("Type three integers ");
int firstInt = userInput.nextInt();
int secondInt = userInput.nextInt();
int thirdInt = userInput.nextInt();
System.out.println(firstInt + secondInt + thirdInt);
}
}
【问题讨论】:
-
请注意,stackoverflow 不是代码编写服务。在寻求帮助之前,请向我们展示您的尝试。
-
好吧,我不知道。对不起。我只是想了解。
-
也许至少显示一些您尝试过的代码?
-
我更新了代码,我知道这很简单,但是我们都必须从正确的地方开始。