I have a switch and an if statement, and they are equivalent. They should both take a string, if yes do something, and if no do another thing. The if statement does nothing regardless of what is entered, but the switch statement does. Why is that?
Here is the if statement:
if (yes.equals("yes")){
System.out.println ("Enter your first number");
fnum = x.nextDouble();
System.out.println ("Enter your second number");
snum = x.nextDouble();
calculations(fnum, snum);
}
if (yes.equals("No")) {
System.out.println("okay, bye then!");
}
Here is the switch:
switch (yesno){
case "yes":
System.out.println ("Enter your first number");
fnum = x.nextDouble();
System.out.println ("Enter your second number");
snum = x.nextDouble();
calculations(fnum, snum);
break;
case "no":
System.out.println("k bye");
This is not a duplicate, because the issue is in the if statement. I have been marked duplicate for my switch.