这是因为您只想让扫描仪要求扫描仪获取下两个输入.
System.out.print("Enter the credits's you will take each term: ");
while (!in.hasNextDouble()){
System.out.print("Enter a valid number: ");
in.next();
}
creditUnits = in.nextDouble();
if (creditUnits < 12){
System.out.print("Enter a number greater than 11: ");
creditUnits = in.nextDouble();
}
System.out.println("You will be taking " + creditUnits + " credits per term.")
另外,您应该考虑的一件事是将if(creditUnits< 12)块放入while循环中,以便您可以连续检查它们是否输入了大于12的数字.
就像是:
System.out.print("Enter the credits's you will take each term: ");
while (true){
System.out.print("Enter a valid number: ");
creditUnits = in.nextDouble();
if (creditUnits < 12){
System.out.print("
Number must be greater than 12!
");
}else
break;
}
System.out.println("You will be taking " + creditUnits + " credits per term.");
同样,也没有愚蠢的问题.只有愚蠢的传单迷. /玩笑