我想把温度、湿度和阳光的值相加,但我不知道为什么它说没有声明“阳光”变量。我希望它能够工作,以便当用户输入“是”时,阳光会被设置为 25,如果他们输入“否”,则它会被设置为 -25。谢谢!
int temperature;
double humidity;
int sunshine;
String temp;
double rating;
temp = JOptionPane.showInputDialog(null, "What temperature is it outside?");
temperature = Integer.parseInt(temp);
temp = JOptionPane.showInputDialog(null, "What percentage of humidity is there?");
humidity = Double.parseDouble(temp);
temp = JOptionPane.showInputDialog(null, "Is it cloudy out?");
if (temp.equals("yes"))
sunshine = 25;
if (temp.equals("no"))
sunshine = -25;
rating = temperature + humidity + sunshine;
慕斯王
相关分类