Ensuring two string are not equal and ignoring case
while(input.!equalsIgnoreCase("W"))
should be
while(!(input.equalsIgnoreCase("W")))
If you are not handling null for input then there can be chance of NullPointerException so I woul do while(!("W".equalsIgnoreCase(input)))
As per the updated code,the solution is
while(!(input.equalsIgnoreCase("W")) && !(input.equalsIgnoreCase("A")) && !(input.equalsIgnoreCase("S")) && !input.equalsIgnoreCase("D")))
{
//Do something
}
Java Does Not Equal (!=) Not Working?
if (!"success".equals(statusCheck))
String is not equal to itself
You are sneaky! The second I is not a lower case latin small i. I hexdumped it:
hexdump -C check
00000000 69 66 20 28 27 69 27 20 3d 3d 20 27 d1 96 27 29 |if ('i' == '..')|
00000010 0a 20 20 20 20 65 63 68 6f 20 27 67 6f 6f 64 27 |. echo 'good'|
00000020 3b 0a 65 6c 73 65 0a 20 20 20 20 65 63 68 6f 20 |;.else. echo |
00000030 27 62 61 64 27 3b 20 20 0a 0a |'bad'; ..|
0000003a
I'll let you look up D1 96 :-) Awesome tricksy riddle. +1
String is not equal to string?
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.if (letters[x].equals(cord[1]))
Use
char
instead ofString
. It's a primitive, so==
will work.char[] letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'L'};
Scanner inp = new Scanner(System.in);
String input = (inp.nextLine());
char[] cord = input.toCharArray();
for (int x = 0; x < 10; x++)
if (letters[x] == cord[1])
System.out.println("Fk yeah!");
Related Topics
Possible to Write Swift Println Logs into File Too
Saving Dictionary into Nsuserdefaults
Play Segment of Avaudiopcmbuffer
How to Use Spritekit Archives with Skspritenode Subclasses
Skscene Becomes Unresponsive While Being Idle
How to Specify the Type Information of an Array That Would Hold Swiftui Custom Views
Does the Initializer of an 'Open' Class Need to Be Open as Well
Access Flutter Sharedpreferences in Swift
How to Access Modifiers of a View in Swiftui
Passing a Variable Through a Segue? Xcode 8 Swift 3
How to Make a Custom Mkannotationview with Xib
How to Use Tabs to Evenly Space Out Description Strings in Swift
Swift Realm: After Writing Transaction Reference Set to Nil
Instance Member 'View' Cannot Be Used on Type 'Gamescene'