Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Loop all pairs

Name: Anonymous 2012-02-05 12:30

Let's say I have this array:

{a, b, c, d, e}

How can I look through all the possible pairs?

a, b
a, c
a, d
a, e
b, c
b, d
b, e
c, d
c, e
d, e

Fictional language syntax please.

Name: HugePenis 2012-02-05 12:52

>>4
Wow, we have someone here who can actually think logically. Anyways, I translated your algorithm to Java. Here is what I came up with.


public class Main {

    public static void main(String[] args) {
        char[] list = {'a', 'b', 'c', 'd', 'e'};

        for (int i = 0; i < list.length - 1; i++) {
            for(int j = i + 1; j < list.length; j++) {
                System.out.println(list[i] + " , " + list[j]);
            }
        }//end for
    }//end main
}


And the corresponding output:

run:
a , b
a , c
a , d
a , e
b , c
b , d
b , e
c , d
c , e
d , e
BUILD SUCCESSFUL (total time: 0 seconds)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List