【发布时间】:2015-12-24 22:57:00
【问题描述】:
所以在这个掷骰子游戏中,用户输入的内容必须遵循 xdy 的格式,其中“x”是骰子的数量,“y”是骰子的面数。如果输入不符合格式,程序应该要求用户输入另一个输入。
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner user_input = new Scanner(System.in);
String input;
System.out.println("Please enter the number and type of dice to roll in the format <number>d<sides>.");
input = user_input.nextLine();
while()
{
System.out.println("Input is not valid. Please enter a new input");
input = user_input.nextLine();
}
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(5);
我的问题是,如何让while 循环检查两个整数之间的字符?
【问题讨论】:
标签: java validation while-loop character dice