• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

key with combinations

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|

If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|

Could anyone please guide me that when the code know how many params, it will return me keys with the valid combination?

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I'm getting this correctly, given a set of arguments, you put | after each param.
After this you remove one or more original params from the string in order to get the keys.
The keys then have to be returned in an array/vector.

Firstly, do you need to have two separate params (a&b) in the first example? If you have an array, will that suffice?
Once you have an input array, the steps may become a lot clearer.

 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacob Sonia wrote:I want to create keys with different combinations.
Let's say i have two params(a, b), then the keys would be like this:
a||
|b|
a|b|


That looks a lot like


If i have 3 params(a,b,c), then the keys would be like this:
a|b|c|
a|||
a||c|
a|b||
|b|c|
|b||
||c|



And that looks a lot like


That's a HUGE hint, by the way.
 
Jacob Sonia
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My concern is that i could have anything in a like 23 and in b like 12333. I want to pass a key already made like this 12|123|123| and when for a and b(the combinations i am looking for), i want the program to append it and create combinations like this:

12|123|123|a||
12|123|123||b|
.....


How is this possible, i am not able to think through it fully.

Thanks
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand what you are trying to do exactly. you have an existing key, like 12|123|123|. Now you are saying you are adding two new fields/pieces, like 'a' and 'b'?

so you will pass a string in, and return an array of strings. Your method will use Jeff's HUGE HINT to generate all the possible things you want to add on. Then you can create a bunch of new Strings by concatenating the passed in string with all the new ones you create.

or have we completely misunderstood what you are trying to do?
 
Jacob Sonia
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

yes i will pass a string to a method and let's say two more params

inputString(String input, String param1, String param2)

the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||

Appreciate any inputs on this.

Thanks
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jacob Sonia wrote:hi,
the output of this method would be
String input | String param1 | |
String input | | String param2|
String input |||


Why not
String input | String param1 | String param2 |

Why is that one left off?

I'll re-iterate what I said before. There are two pieces. your method needs to build all the possible pieces that can be added on, like this:
|||
param1||
||param2|
|param1|param2|

and then, for each one, it needs to append it onto the end of 'input'.

Note that you probably don't want a method signature of "inputString(String input, String param1, String param2) ". If you did it that way, you'd need a new method every time you wanted to add another param...

inputString(String input, String param1, String param2, String param3)
inputString(String input, String param1, String param2, String param3, String param4)
inputString(String input, String param1, String param2, String param3, String param4, String param5)
etc...

you probably want

inputString(String input, String [] pieces)

Then you write your method to process the pieces array.
 
Jacob Sonia
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fred,

Yes you are right and thanks for the tips, but i am still not sure how to implement it. Any tips would be great.

Thanks
 
fred rosenberger
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok...it works better around here if you

  • ask specific questions
  • post your code so far
  • tell us what you expect your code to do
  • tell us what your code does

  • Generic questions like "I need help" or "show me how to do this project" are generally met with silence. Right now, it looks like you have put zero effort into doing this. If you have put in zero effort, why do you expect anyone else to put in any more effort?

    You've been given several suggestions throughout this thread, and only come back with "yeah, I need help writing this code".

    My first suggestion would be to try writing SOMETHING...ANYTHING...to at least get started.
     
    You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
    Smokeless wood heat with a rocket mass heater
    https://woodheat.net
    reply
      Bookmark Topic Watch Topic
    • New Topic