# Thread: Possible combinations for a n- digit number???

1. Newbies
Join Date
May 2011
Posts
3
Rep Power
0

## Possible combinations for a n- digit number???

Hai Gurus,

Can somebody suggest ,me the logic or the code to get the generalised form for finding the possible combinations for a a n-digit number?

Ex: If I input the number as 1234 it should give the output as all the possible 4! combinations that can be derived by the 4 digits in it.

Here is my work on the 3- digit number!! :p

import java.io.*;
class x5
{
public static void main(String args[])throws IOException
{
int x;
System.out.print("\n Enter the 3 digit number:");
int a=x/100; //5
int b=x/10; //56
b=b%10;//6
int c=x%10;//8
System.out.println("Possible combinations using the number "+x+ " are:");
System.out.println(((a*100)+(b*10)+c)+" "+((a*100)+(c*10)+b)+" "+(a+(b*10)+(c*100))+" "+((a*10)+b+(c*100))+" "+((b*100)+(a*10)+c)+" "+((b*100)+(c*10)+a));
}
}

2. You are looking to find all the possible permutations of an n digit number?

Show us an example of a 3 digit number worked out by hand, let's say 2, 3, 4. Try to look for a pattern. To found out how many actual combinations an n digit number can produce, try with a few small numbers by hand and look for a pattern.

3. Also, as a bit of advice it would be helpful to create some helper methods, one can take some n digit number and split it into an n digit array(either mathematically, or via string conversion) and another helper method can take an array and generate a list of all possible permutations.

4. Newbies
Join Date
May 2011
Posts
3
Rep Power
0
I did that...
But while trying for the four digit number we have to ensure that fpr each digit we repeat the 3- digit code...
But I m lacking on how to generalise it... We can derive answers if we want to manually write the combinations for the 4- digit code but we want to generalise it!!

5. Newbies
Join Date
May 2011
Posts
3
Rep Power
0
And also thanks dude for ur reply....

#### Posting Permissions

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