前半部分代码确定您是男性还是女性。下半部分代码的答案取决于男人还是女人。但是当我进入“男人”时,它仍会打印女人的代码。请帮忙
Scanner scan1 = new Scanner(System.in);
System.out.println("Are you a man or woman?");
String user_inputs_sex = scan1.nextLine();
String user_sex = user_inputs_sex;
if (user_inputs_sex.equalsIgnoreCase("MAN"))
{
user_sex = man;
}
else if (user_inputs_sex.equalsIgnoreCase("WOMAN")
{
user_sex = woman;
}
System.out.println("Having a good day?");
if ((user_answer.equalsIgnoreCase("YES")) && (user_sex.equals(woman)))
{
System.out.println("Glad to hear that ma'am");
}
// when I enter "man" in the previous code it still prints out this code
else if
((user_answer.equalsIgnoreCase("NO")) && (user_sex.equals(woman)))
{
System.out.println("Sorry to hear that ma'am");
}
// here is same code as above but for a man