CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2015
    Posts
    1

    All possible combination code

    Hi, I am writing code which write down all possible combinations (of a1,a2,a3,b1,b2,b3,c1,c2,c3 in line of three) in 2d array. Basically the answers suppose to be:
    a1b1c1
    a1b1c2
    a1b1c3
    a1b2c1
    ...
    a3b3c3
    Actually, in program I don't need a, b, c letters. I need only integers, so the answer suppose to be in 2d array and look like this:
    111112113121122123131...333

    Here is my program concept. I don't know how to set a, b, c sequence in array.
    Code:
    public class Main {
    
    public static void main(String[] args) {
            
    double [] [] myArray = new double [1][27];
    int a = 0;
    int x =
    int y =
    int z =
    for(int j=0; j<3; j++)
    {
    a++;
    myArray[0][x] = a;
    for(int i=0; i<3; i++)
    {
    b++;
    myArray[0][y] = b;
    int c = 0;
    for(int f=0; f<3; f++)
    {
    c++;
    myArray[0][z] = c;
    }
    for(int p=0; p<myArray[0].length; p++)
    {
    System.out.println(myArray[0][p]);
    }
    }
    }

  2. #2
    Join Date
    Apr 2015
    Posts
    3

    Re: All possible combination code

    That is all combinations of the alphabet {a,b,c} with the string length set to 3. The code I have written is functional, however I'd like to read what ...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured