#Can you please tell me why it is not working?
19 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @normal knoll! Please use
/closeor theClose Postbutton 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.
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
variable yes?
yes
change yes to "yes"
if (fur.equals(yes)) {
System.out.println("it is a mammal");
}```
why so complicated
also use .equals not == for string comparison
Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.
or
System.out.println("it is a mammal");
}```
Everyone starts at one point i guess
it's better to use "yes".equals(fur), if you don't want to have nullpointerexception