Won't recall variable from within boolean expression <p>I'm having trouble finding what exactly java is having trouble with when recalling a variable. I'm creating a simple chatbot and this is what I have so far:</p> <pre><code>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")&lt;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")){ } } } </code></pre> <p>My problem is that java won't recognize the variable city within the if else statements and so says city is not resolved. How do I get java to recognize the objects within a boolean expression? What am I doing wrong?</p>