Java初学者。使用以下代码,我的其他功能会自动打印。所以即使在回答问题之前,你想和你的伴侣一起买房子吗?输入是/否'它已经抛出了其他功能。
//How much is the gross salary
boolean partner;
String partnerQuestion;
double partnerSalary =0;
System.out.print("Do you want to buy the house with your partner? Type Yes / No \n");
while(true){
partnerQuestion = sc.nextLine().trim().toLowerCase();
if(partnerQuestion.equals("yes")){
//how high is the loan
System.out.print("What is your partners´ anually gross salary? \n");
partnerSalary = sc.nextDouble();
partner = true;
break;
}
else if(partnerQuestion.equals("no")){
partner = false;
break;
}
else{
System.out.print("I did not understand you. Please try again.");
}
}
为了给出一个好的图片,我在这个while循环中的if / else确实有效。
boolean timeTF;
double term;
System.out.print("For how many years should the mortgage run? Choose between 10/15/20/25/30 \n");
while(true){
term = sc.nextDouble();
if(term != 10 && term != 15 && term != 20 && term != 25 && term != 30){
System.out.print("Please type 10/15/20/25/30, other values are not valid \n");
timeTF = true;
}
else{
timeTF = false;
break;
}
}
所以我的问题是,我错过了什么?提前谢谢。