So I have this tenary operator:
public class Tenary {
public static void main(String[] args) {
String gender = "MR";
System.out.println( (gender.equals("male")) ? "Mr." : "Ms.");
}
}
And regardless it always prints out "Ms." I am confused as to why. Is this a default setting. Setting the string to a female or male name would make little difference as I have already tried that. How would I go about actually assigning a name that corresponds to the title? For some reason, it makes slightly more sense to conceptualize this in the if/else block. But, I suppose the issue I am having is knowing how the computer would distinguish a male and female name? Or am I overthinking it?
Aucun commentaire:
Enregistrer un commentaire