-2
else if (answer.equals("check value")){
System.out.println("Of what?");
System.out.println("Tax, Donations, Income, Profit, Expenditure, Services, Military, City or Economy.");
System.out.println("Do not use caps and spell it correctly otherwise it will not be recognised.");
String valueToCheck = scan.nextLine();
if (valueToCheck == "tax"){
System.out.println(tax);
}else if (valueToCheck == "donations"){
System.out.println(donations + "donations per turn");
}else if(valueToCheck == "income"){
System.out.println(incomePerTurn + " income per turn");
}else if(valueToCheck == "profit"){
System.out.println(profitPerTurn + " profit per turn");
}else if(valueToCheck == "expenditure"){
System.out.println(expenditurePerTurn + "expenditure per turn");
}else if(valueToCheck == "services"){
System.out.println(servicesBudget + " to services budget");
}else if(valueToCheck == "military"){
System.out.println(militaryBudget + " to military budget");
}else if(valueToCheck == "city"){
System.out.println(cityBudget + " to cities budget");
}else if(valueToCheck == "economy"){
System.out.println(economy + " to total economy");
}
newTurn();}
你好,每当我运行我的程序并键入'检查值'我没有得到任何错误,事实上我什么也没有得到。我只是想知道为什么没有返回。谢谢你的帮助!我的程序不打印变量
请添加来自'else if'的代码。 –
这可能是不足以帮助我们的代码。但是你做错的一件事是使用'=='进行字符串比较。改用'.equals()'。 –
您认真在'answer'上使用'equals',但不在'valueToCheck'上使用? – rgettman