#Can you please tell me why it is not working?

19 messages · Page 1 of 1 (latest)

normal knoll
#

Can you please tell me why it is not working?It says: "yes" cannot be resolved to a variable

silk prismBOT
#

This post has been reserved for your question.

Hey @normal knoll! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

normal knoll
#

package ilkprojem;
import javax.swing.JOptionPane;
public class Main {

public static void main(String[] args) {
    

    
    
    JOptionPane.showMessageDialog(null,"Please respond with either yes or no");
    
    String fur = JOptionPane.showInputDialog("Does it have fur?");
    

    if (fur == yes) {
        System.out.println("it is a mammal");
    }
    else {
        System.out.println("it is not a mammal");
    }
    
    
    
    
}
#

here is my code

normal knoll
#

yes

green thunder
#

change yes to "yes"

silk nest
#
if (fur.equals(yes)) {
    System.out.println("it is a mammal");
}```
green thunder
silk prismBOT
#

Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.

silk nest
#

or

    System.out.println("it is a mammal");
}```
normal knoll
#

Thank you

#

I'm really new

green thunder
#

Everyone starts at one point i guess

sage pike
#

it's better to use "yes".equals(fur), if you don't want to have nullpointerexception

normal knoll
#

I did a terrible mistake of not putting double quotes

#

Thx