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:");
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
x=Integer.parseInt(br.readLine());//568
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));
}
}