我一直在互联网上搜索,似乎找不到这个答案 那么有谁知道如何阻止用户输入只允许数字的字母?
这是我的代码到目前为止的样子。
public static double payCalculator(double hours, double basePay)
{
double totalPay;
double overTime = 8.00 * 1.5;
while(hours < 0 | hours > 60) {
System.out.println("Cannot work more than 60 hours a week");
System.out.println("Hours Work?");
hours = in.nextDouble();
}
while(basePay < 8) {
System.out.println("Base Pay cannot be less than 8");
System.out.println("Base Pay?");
basePay = in.nextDouble();
}
if
(hours <= 40){
totalPay = hours*basePay;
}
else {
totalPay = ((hours - 40)*overTime) + (40*basePay);
}
return totalPay;
}
public …Run Code Online (Sandbox Code Playgroud)