在调用变量时,我很难找到 java 到底遇到了什么问题。我正在创建一个简单的聊天机器人,这就是我目前所拥有的:
public class Chatbot {
public static void main(String[] args) {
String name = JOptionPane.showInputDialog("Hi! How are you? My name is Chatbot! What is yours? ");
if (name.compareTo("a")<0){
String city = JOptionPane.showInputDialog("Nice to meet you! Where are you from, "+name);
}
else
{
String city = JOptionPane.showInputDialog("Huh. That's a strange name. Where are you from,"+name);
}
if (!city.equals("Seattle")){
}
}
}
我的问题是 java 无法识别 if else 语句中的变量 city ,所以说 city 没有解决。如何让 java 识别布尔表达式中的对象?我究竟做错了什么?