String[] letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "L"};
Scanner inp = new Scanner(System.in);
String input = (inp.nextLine());
String[] cord = input.split("");
for(int x = 0; x < 10; x++)
if(letters[x] == cord[1])
System.out.println("Fk yeah!");
Why the Fk yeah! never happens if I input one of A-L letters?
Best Answer
Strings are objects. The
==
compares objects by reference, not by their internal value.There are 2 solutions:
Use
String#equals()
method instead to compare the value of twoString
objects.Use
char
instead ofString
. It's a primitive, so==
will work.