0

I have a little problem with my first JOptionPane program. I don't get my if-statements to output anything. What did I do wrong?

package test1;

import javax.swing.JOptionPane;

public class Lol1 {
  public void test() {
    String res;
    res = JOptionPane.showInputDialog("Does this work?");
    if (res == "Yes") {
        JOptionPane.showMessageDialog(null, "Good."); 
    }
    if (res == "No") {
        JOptionPane.showMessageDialog(null, "You're lying."); 
        }
}



public static void main(String[] args) {
    Lol1 l1 = new Lol1();
    l1.test();
    }
}
  • Your problem is that you have to use the equals method, not ==. – GhostCat Oct 17 '16 at 17:54
  • Isn't '==' to test equality and '=' assign? If i use '=' I get more problems. – cawe011 Oct 17 '16 at 17:59
  • Programming is about paying attention to details, like A) I wrote about **equals** method, not about assignment operator (=) B) Your question already got an "already answered" link up there. Digest that information first before coming up with the next question please. – GhostCat Oct 17 '16 at 18:16
  • You're right. Thank you. I learned a lot from the answers you submitted. It feels like I got screwed over by the paper I got from my professor. – cawe011 Oct 17 '16 at 20:06

0 Answers0