Results 1 to 5 of 5
  1. #1
    anishr6 is offline Newbies
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Question 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));
    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.


    Also, please use code tags, [code] YOUR CODE HERE [/code]

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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. #4
    anishr6 is offline Newbies
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    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. #5
    anishr6 is offline Newbies
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 01-23-2011, 01:37 AM
  2. 4 digit restriction
    By GTM in forum Java Applets
    Replies: 3
    Last Post: 12-28-2010, 03:26 AM
  3. select a digit in a number
    By navid in forum New To Java
    Replies: 3
    Last Post: 12-12-2010, 11:47 AM
  4. All possible combinations given a binary number
    By LeanA in forum New To Java
    Replies: 9
    Last Post: 06-18-2010, 06:33 PM
  5. convert getValue result in a 4 digit number
    By roseline43 in forum New To Java
    Replies: 0
    Last Post: 09-02-2008, 09:44 PM

Posting Permissions

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