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

• 05-25-2011, 08:25 AM
anishr6
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));
}
}
• 05-25-2011, 08:45 AM
sunde887
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.