Comparing String Strings in Java [Duplicated]

0

Question from an ignoramus, in java, why does not this work?

nombre = S.nextLine();
nombre= nombre.toLowerCase();
if(nombre.equals("juan") || nombre.equals("pedro"))
{
...
}

I take it as always different, like the String can not be compared by passing the else as the correct option.

    
asked by Cosoforo Decimo 15.08.2017 в 03:50
source

1 answer

1

Try only using: name = S.next ();

When using nextLine (), consider the line where you press the enter.

Tell us, Greetings _!

    
answered by 15.08.2017 в 03:59