我正在尝试制作一种询问用户金额的方法,然后它检查金额是否> 0,如果它是循环结束,如果输入不是> 0,则循环继续,直到输入正确的数据。我无法弄清楚我的问题..
/** Get principal amount **/
public static double getPrincipalAmount(double numb1) {
Scanner input = new Scanner(System.in);
do {
System.out.print("Enter Loan Amount: ");
double numb1 = input.nextDouble();
double getPrincipalAmount = 0;
if (numb1 > 0) {
getPrincipalAmount = numb1;
} else {
System.out.println("Data Error: Loan amount must be greater than zero. You entered " + numb1);
}
} while (numb1 < 0);
return getPrincipalAmount;
}