Skip to content

Instantly share code, notes, and snippets.

@CompSciRocks
Created November 27, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CompSciRocks/08b73401f2fd359c66063479b4660634 to your computer and use it in GitHub Desktop.
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/
public int numMatches() {
int cnt = 0;
for (WordPair wp: allPairs)
if (wp.getFirst().equals(wp.getSecond())
cnt++;
return cnt;
}
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]);
}
@kidsfreej
Copy link

Error in the code. "i<words.length-1" is the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment