- Joined
- Apr 5, 2004
- Location
- Louisiana
Im trying to teach myself if else statements so I wrote a short example proggy just to play and learn. I thought I had it but it dosent work. It always reverts to the else?
public class Brain {
String name;
String location;
String age;
String sex;
public void person() {
name = JOptionPane.showInputDialog("Hey there, whats your name?");
location = JOptionPane.showInputDialog("well " + name +" where ya from?");
age = JOptionPane.showInputDialog("well ****, I dont know anything about " + location +". anywho, how old did you say you are?");
sex = JOptionPane.showInputDialog("well " + name +" are you a boy or a girl");
if (sex == "Boy") {JOptionPane.showMessageDialog(null, "sorry but I only talk to females");}
else if (sex == "boy") {JOptionPane.showMessageDialog(null, "sorry but I only talk to females");}
else if (sex=="girl") {JOptionPane.showMessageDialog(null, "*Well thats nice","A girl?",JOptionPane.PLAIN_MESSAGE);}
else if (sex=="Girl") {JOptionPane.showMessageDialog(null, "Well thats nice","A girl?",JOptionPane.PLAIN_MESSAGE);}
else {JOptionPane.showMessageDialog(null, "no speaky english?");}
System.exit(0);
}
}
public class Brain {
String name;
String location;
String age;
String sex;
public void person() {
name = JOptionPane.showInputDialog("Hey there, whats your name?");
location = JOptionPane.showInputDialog("well " + name +" where ya from?");
age = JOptionPane.showInputDialog("well ****, I dont know anything about " + location +". anywho, how old did you say you are?");
sex = JOptionPane.showInputDialog("well " + name +" are you a boy or a girl");
if (sex == "Boy") {JOptionPane.showMessageDialog(null, "sorry but I only talk to females");}
else if (sex == "boy") {JOptionPane.showMessageDialog(null, "sorry but I only talk to females");}
else if (sex=="girl") {JOptionPane.showMessageDialog(null, "*Well thats nice","A girl?",JOptionPane.PLAIN_MESSAGE);}
else if (sex=="Girl") {JOptionPane.showMessageDialog(null, "Well thats nice","A girl?",JOptionPane.PLAIN_MESSAGE);}
else {JOptionPane.showMessageDialog(null, "no speaky english?");}
System.exit(0);
}
}