Created
November 27, 2018 16:01
-
-
Save CompSciRocks/08b73401f2fd359c66063479b4660634 to your computer and use it in GitHub Desktop.
WordPair solution for the 2018 AP Computer Science Exam - https://compsci.rocks/wordpair-solution/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int numMatches() { | |
int cnt = 0; | |
for (WordPair wp: allPairs) | |
if (wp.getFirst().equals(wp.getSecond()) | |
cnt++; | |
return cnt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public WordPairList(String[] words) { | |
allPairs = new ArrayList<>(); | |
for (int i=0; i<words.length; i++) | |
for (x=i+1; x<words.length; x++) | |
allPairs.add(new WordPair(words[i], words[x]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error in the code. "i<words.length-1" is the answer