What you are missing is not checking the input value. First check the input value…:
System.out.println(input);
…and see if the value is ok. Then you can say if your “if-else
” component is working or not.
Also delete the gap @ input.equals ("Hola")
. it must be input.equals("Hola")
Addition: You cannot use ==
operator for Strings in Java. You can use var.equals("something")
to check if variable var
equals to "something"
.
Addition 2: You must use scanner.nextLine()
to get typed string completely instead of using scanner.next()
because next()
gets the next WORD.
And here is your working code:
19
solved Java else if with strings not working – Scanner(System.in); [duplicate]