Results 1 to 17 of 17
  1. #1
    raviraj18 is offline Member
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default java programming quesion

    Hi Friends , Please help me to write program to get out put as given below

    note : The List will contain N Strings ..

    List<String> list1=new ArrayList<String>();

    list1.add( GP100);
    list1.add( GP200);
    list1.add( GP300);


    i want the combinations like

    [GP100 , GP200] ,[GP100 , GP300] ,[GP100 , GP200][GP200 , GP300][GP300 , GP100] ...so on and also [GP100 , GP200,GP300] , [GP200 , GP100,GP300] ..so on

    please help me ...

  2. #2
    2by4 is offline Banned
    Join Date
    Dec 2011
    Posts
    143
    Rep Power
    0

    Default Re: java programming quesion

    First design your basic format [?, ?, ?].

    Then think about repetition and recursion in order to build it up.

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    Quote Originally Posted by raviraj18 View Post
    i want the combinations like

    [GP100 , GP200] ,[GP100 , GP300] ,[GP100 , GP200][GP200 , GP300][GP300 , GP100] ...so on and also [GP100 , GP200,GP300] , [GP200 , GP100,GP300] ..so on
    I think your example is incorrect (and therefore confusing). Why is GP100, GP200 in that list twice?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: java programming quesion

    java programming quesion
    Recommended reading: Use meaningful, specific subject headers

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: java programming quesion

    Moved here from 'Advance Java' as there's nothing 'advanced' about the question.

    In future, please post beginner questions in this section.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: java programming quesion

    Are you trying to make permutations of the input? Or just a set of pairs?

  7. #7
    NModern is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Re: java programming quesion

    Java Code:
    String[] array = {"GP100", "GP200", "GP300"};
    String[] array2 = {};
    for(int i=0;i<array.length;i++){
          for(int a=0;a<array.length;a++){
               array2.push(array[i]+"-"+array[a]);
          }
    }
    dont know syntax is right or not. I am beginner. But you got the way.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    But then you get all values 3*3:

    GP100-GP100
    GP100-GP200
    GP100-GP300
    GP200-GP100
    GP200-GP200
    GP200-GP300
    GP300-GP100
    GP300-GP200
    GP300-GP300

    Is this what you want?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    NModern is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Re: java programming quesion

    But he wants gp100-gp200-gp300, gp100-gp300-gp200, gp200-gp100-gp300, gp300-gp100-gp200, gp300-gp200-gp100 too...

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    Quote Originally Posted by NModern View Post
    But he wants gp100-gp200-gp300, gp100-gp300-gp200, gp200-gp100-gp300, gp300-gp100-gp200, gp300-gp200-gp100 too...
    Do you want all permutations of those three values? Please clearly state what you actually want (e.g. give a small but complete example).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    NModern is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Re: java programming quesion

    Java Code:
    String[] array = {"GP100", "GP200", "GP300"};
    String[] array2 = {};
    for(int i=0;i<array.length;i++){
          if(i==0){
            for(int a=0;a<array.length;a++){
               array.push(array[a]);
            }
          }
          else{
              for(int b=0;b<array2.length;b++){
                       for(int c=0;c<array.length;c++){
                                 array2.push(array2[b]+"-"+array[c]);
                       }
              }
          }
    }
    // there will be duplicates. to remove them
    String[] array3 = {};
    for(int i=0; i<array2.length; i++){
             if(!Arrays.asList(array3).contains(array2[i])){
                  array3.push(array2[i]);
             }
    }
    I think it will help you. i havn't checked if this working or not.
    Last edited by NModern; 12-21-2011 at 08:55 PM.

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    Please no (incorrect) algorithms for now; suppose I have three 'things' A, B and C. What are the results? (just list them here).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default Re: java programming quesion

    That's not the OP.
    That's a little helper...possibly one of Santa's.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    Quote Originally Posted by Tolls View Post
    That's not the OP.
    That's a little helper...possibly one of Santa's.
    Hm ... I didn't see a red nose anywhere, so it's not Rudolf. Dancer mayhap?, Dasheer? Prancer? Vixen? Comet by any chance? Cupid? Donner? Blitzen?

    kindest regards,

    Jos ;-)
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    NModern is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Re: java programming quesion

    if you see I'm not the user asking question(raviraj18). I only wanted to help him to write the algorithm. I know that my algorithm is not Java algorithm. Because I am a newbie in Java. I am a web programmer and I know PHP and the code I wrote I think must work in PHP if written in right syntax and will give the result HE asked.

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default Re: java programming quesion

    Quote Originally Posted by NModern View Post
    if you see I'm not the user asking question(raviraj18). I only wanted to help him to write the algorithm. I know that my algorithm is not Java algorithm. Because I am a newbie in Java. I am a web programmer and I know PHP and the code I wrote I think must work in PHP if written in right syntax and will give the result HE asked.
    My guess is that the OP wants all permutations of all combinations C(n,k); e.g. if the elements are A, B and C, the OP seems to want the following:

    A
    B
    BA, AB
    C
    CA, AC
    CB, BC
    CBA, CAB, BAC, BCA, ABC, ACB

    but that's just a guess ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    NModern is offline Member
    Join Date
    Jul 2010
    Posts
    22
    Rep Power
    0

    Default Re: java programming quesion

    Yeah he want all of the combinations. And I think the algorithm I wrote must give him the result. Or not?

Similar Threads

  1. Java Security Quesion
    By venk123 in forum New To Java
    Replies: 3
    Last Post: 03-04-2011, 07:03 AM
  2. quesion - how to display an array in an applet?
    By EBBOOO in forum New To Java
    Replies: 14
    Last Post: 06-05-2010, 05:29 PM
  3. Replies: 1
    Last Post: 05-31-2009, 10:57 PM
  4. Replies: 1
    Last Post: 05-31-2009, 02:17 PM
  5. Replies: 16
    Last Post: 05-28-2009, 03:41 PM

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
  •