Programming Question Help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    Programming Question Help

    Probably a very easy question for most of you guys out there but I
    simply can't get to figure out how to do this

    Suppose that I have an unknown number of items (A,B,C,etc...) and each
    item contain an unknown number of elements(e.g A1,A2,A3,A4, B1,B2, C1)

    How would I go around writing a java code to give me the possible
    combinations(in that case 8)of A B and C in that order?
    i.e.
    A1 B1 C1
    A1 B2 C1
    A2 B1 C1
    A2 B2 C2
    A3 B1 C1
    A3 B2 C2
    A4 B1 C1
    A4 B2 C2

    Help pls
  • Joe

    #2
    Re: Programming Question Help

    In article <9683a32b.03092 60707.3ed5efac@ posting.google. com>,
    cysy80@hotmail. com says...[color=blue]
    > Probably a very easy question for most of you guys out there but I
    > simply can't get to figure out how to do this
    >
    > Suppose that I have an unknown number of items (A,B,C,etc...) and each
    > item contain an unknown number of elements(e.g A1,A2,A3,A4, B1,B2, C1)
    >
    > How would I go around writing a java code to give me the possible
    > combinations(in that case 8)of A B and C in that order?
    > i.e.
    > A1 B1 C1
    > A1 B2 C1
    > A2 B1 C1
    > A2 B2 C2
    > A3 B1 C1
    > A3 B2 C2
    > A4 B1 C1
    > A4 B2 C2
    >
    > Help pls
    >[/color]

    One way is to use two loops. The outer loop steps through the number of
    items and the inner loop steps through the elements in each item. If you
    cannot programmaticall y determine the number of items or elements prior
    to entering the loop, then an iterator is more useful. Alternatively, you
    can place a "sentinel" value (i.e. null) at the end of the list and,
    instead of loopping use while (!null){ } .











    --

    Fuck George W. Bush!!!

    Comment

    • Chris

      #3
      Re: Programming Question Help

      The problem is the number of items and the number of elements can only
      be determined at runtime. anyone care give a short pseudo code of a
      possible solution pls? thx

      Joe <sfjoe@spamcop. net> wrote in message[color=blue]
      > One way is to use two loops. The outer loop steps through the number of
      > items and the inner loop steps through the elements in each item. If you
      > cannot programmaticall y determine the number of items or elements prior
      > to entering the loop, then an iterator is more useful. Alternatively, you
      > can place a "sentinel" value (i.e. null) at the end of the list and,
      > instead of loopping use while (!null){ } .[/color]

      Comment

      Working...