dimanche 5 juillet 2015

String Comparision in if condition always errors

This looks like the simplest of all the codes and yet, it is uncompilable. I am completely frustrated with this. Please help.

here is what I'm doing - I break a string of words into Array of Strings. I then further split the string in the 2nd index of the array and do my compariso (only if is of length 16). Below are the conditions - the first half must be all digits and greater than zero. the second half must equal to "-default" (non-case sensitive).

for some reason, the if condition is always unacceptable for 2nd half comparison.

if (linearray[2].length() == 16) {
        String first8 = linearray[2].substring(0, 7);
        String last8 = linearray[2].substring(8, 15);
        String value = "-default";      
        try {
            int isNum = Integer.parseInt(first8);
            if (isNum > 0) {
                return "Correct";
            } else {
                return "Incorrect";
            }
        } catch (NumberFormatException e) {
            return "Incorrect";
        }
        //---------------HERE IS THE ISSUE--------------
        if (last8.equals(value)) {

        }
    }

Aucun commentaire:

Enregistrer un commentaire