So I'm currently learning Java & have been watching thenewboston but I'm wanting to see if what the user types is x then do x hopefully that makes sense.
If you could leave an example it would help me a lot.
So I'm currently learning Java & have been watching thenewboston but I'm wanting to see if what the user types is x then do x hopefully that makes sense.
If you could leave an example it would help me a lot.
Use the string1.equals(string2)
method:
String expected = "hello, world";
if(input.equals(expected)){
//Do something
}
This method returns true if the two strings are equal and false if they are not. You cannot just use ==
as this compares the pointers/references of the strings, and not the strings' content.
Edit: You can read input by using a Scanner.