Forums Register Login

How to make combination function generic

+Pie Number of slices to send: Send
Hi all,

I have written a function which generates combination in a desired order. The code is somthing like this



The output of this code is and this is what is required :



My problem is all the hard coding in that function i am passing "min" "max" for range of digits and this part is ok (more or less)
Please ignore the Boolean value.

"noOfControls" is something i need to implement ie all the combination i am getting are 3 digits max (governed by number of for loop).

I need to remove this dependency i don't want to write new method every time say "if i need series upto 6 digits and write method with 6 loops"

My question is what should be the approach ?
and what are the possible ways to do it.

Thanks in advance.
+Pie Number of slices to send: Send
Check out recursion. You create a private method that takes the number of elements to add. When initially called with 6, you take one element, then call the same method but with 5 this time. Continue until the count is 1.
See where your hand is? Not there. It's next to this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2208 times.
Similar Threads
Generating random numbers with given properties
priority queue based on unsorted list(Java's LinkedList Class)
Invalid column type
Array's & Vector
Simple ArrayList conundrum?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:28:16.