The most likely case here can be that the answer has leading/trailing white spaces. You need to trim()
those out.
if (answer.trim().equals("OK")) {
You did not initially mention in the question that the answer had extra string besides “OK”. In that case, you either need to remove other stuffs(using a regex may be), or use the contains()
method to check if the answer string contains “OK” in it.
if (answer.contains("OK")) { // check if answer contains the string "OK"
3
solved How to equal php answer?(.equals not working) [closed]