I've been trying to compare a string which is stored in two diffrent variables(but the content is same). I get the two same inputs from user..
package switchcasepgm;
import java.util.Scanner;
public class stringcomp {
public static void main(String[] args)
{
Scanner getinp=new Scanner(System.in);
System.out.println();
String sdr = getinp.nextLine();
System.out.println();
String rds = getinp.nextLine();
if(sdr==rds)
{
System.out.println("succ");
}
else
{
System.out.println("fail");
}
}
}
But the output always returns the else statement.. here's the output..
yes
yes
fail
even i tried for if(sdr=="yes"), it to returns only the else statement.. I've tried for many possibilites, but not get it..