change candidate==str[i] to candidate.equals(str[i])
sophisticated method using lots of if-else