-3
Scanner na=new Scanner(System.in);
String s;
out.print("enter the value in s=");
s=na.nextLine();//entering value at runtime
out.println("value in s="+s);//check here the value in s
if(s=="ERROR")
   out.println("error is received ");
else if(s=="SUCCESS")
   out.println("success is executed ");
char c[];
c=s.toCharArray();
out.println("length of string s="+c.length);

in this case why if statement or else statement donot work but if we input the value in string at compile time it executes so why not at runtime we usually compare two values by '==' operator so why not we can compare two string by using this operator there are various other methods available for comparing two strings i mean that,s ok but why == operator is not suitable for comparing strings or why == operator fails to compare two strings

Naman
  • 7
  • 5

1 Answers1

-1

it should be

(s).equals("ERROR")