I just don't understand why "if" statement always get "false". Can someone explain me it, pls?
import java.util.Scanner; public class Test { public static void main(String[] args) { String b, c; Scanner scanText = new Scanner(System.in); System.out.print("Enter key word: "); b = scanText.next(); //typing "key" System.out.print("Enter key word once again: "); c = scanText.next(); //once again typing "key" if(c == b) System.out.println("Access allowed."); else System.out.println("Access denied."); } }
Why I can't reach "Access allowed."?
Not if(c == b), nor if("key" == b) or if( (c="key") == b).
Thank you in advance for your help.