I've been wondering about what is wrong with my code
String s = JOptionPane.showInputDialog(null,"Enter discount type");
if(s == "PWD"){
dis = 0.25;
}
else{
dis = 0;
JOptionPane.showMessageDialog(null, s);
}
when I run my program, it performs the code in the 'else' block instead of doing what is in the 'if' block. Thanks!
==
tests for reference equality (whether they are the same object).
.equals()
tests for value equality (whether they are logically "equal").
Objects.equals()
checks for nulls before calling .equals() so you don't have to (available as of JDK7, also available in Guava).
try like this
if(s.equals("PWD"))