-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