Skip to content

Instantly share code, notes, and snippets.

@tmosest
Created January 24, 2017 22:59
Show Gist options
  • Save tmosest/0a001830d95860d18d2d34f45ecb9bc0 to your computer and use it in GitHub Desktop.
Save tmosest/0a001830d95860d18d2d34f45ecb9bc0 to your computer and use it in GitHub Desktop.
Print Unordered Pairs
public static void printUnorderedPairs(int[] array) {
for(int i = 0; i < array.length - 1; i++)
for(int j = i + i; j < array.length; j++)
System.out.println("(" + array[i] + ", " + array[j] + ")");
}
/*
Note that 1 + 2 + 3 + 4 + 5 + ..+ n = (n * (n + 1)) / 2
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment