我的循环问题
public static void me() {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("##0.00");
int mew = 0;
double mes = 0;
boolean Curve = true;
int cBool = 0;
double cNum = 0;
double mers = 0;
double wmes = 0;
//Input Midterm weight and score
System.out.println("\nMidterm exam:");
System.out.print("\tWhat is its weight (0-100)? ");
mew = input.nextInt();
System.out.print("\tExam Score ");
mes = input.nextDouble();
while (Curve){
System.out.print("\tWas there a curve? (1 for yes, 2 for no) ");
cBool = input.nextInt();
if (cBool == 2)
Curve = false;
else
System.out.print("\tHow much was the curve? ");
cNum = input.nextDouble();
Curve = false;
}
//calculate weighted Midterm score
mers = (mes+cNum);
if (mers > 100)
mers = 100;
wmes = ((mers/100)*mew);
System.out.println("\tWeighted Exam score: " + df.format(wmes));}
}
问题是当我为cBool输入2时它不会继续下一步,但是如果我为cBool输入1然后给cNum一个数字它将继续下一步
答案 0 :(得分:2)
您是否尝试隔离else块中存在的所有指令? 由此:
else
System.out.print("\tHow much was the curve? ");
cNum = input.nextDouble();
Curve = false;
对此:
else
<强> {强>
System.out.print("\tHow much was the curve? ");
cNum = input.nextDouble();
Curve = false;
<强>} 强>