lundi 21 janvier 2019

If statement does not print out the body when the condition has met

I expect the output will be the string in the wordList when it matched the search before the for loop exits but it does not print out every time when the if statements met the condition.

search = "ABC"
wordList = [["ABC", "123"], ["ABC", "456"], ["DEF", "123"]]

public void biDi(String searchWord, String[][] wordList) {
    int start = 0; 
    int end = list.size ()-1;
    String search = searchWord;

    int path = 0;
    for (int i = 0; (i < (list.size ()/2)); i++) {
        if (search == wordList[start][0]) {
            System.out.println (wordList[start][1]);
        }
        if (search == wordList[end][0]) {
            System.out.println (wordList[end][1]);
        }

        start++;
        end--;
        path++;
    }

    System.out.println (path);

}

Aucun commentaire:

Enregistrer un commentaire