kaisen adina

Greenhorn

Posts: 2

posted 4 years ago

im making a program that will show the number of possible combination of

what the user inputs and number of takes at a time...

i already finished making showing the number of possible combination but

i am having problem in showing the actual items of combination of the inputted...

to make it more easy to understand...

for example

the user input " apple banana cherry mango orange"

number of takes at a time: " 3 "

the output will show the formula and computation and the total number of combinations:

for example the answer is " 10 "

now here comes the problem.

i need to show the possible combinations of the items if the total combinations is less or equal to 10

apple banana cherry mango orange by taking 3 at a time

example

apple banana cherry

apple banana mango

apple banana orange

apple cherry mango

apple cherry orange

apple mango orange

banana cherry mango

banana cherry orange

banana mango orange

cherry mango orange

thank you in advance guys

what the user inputs and number of takes at a time...

i already finished making showing the number of possible combination but

i am having problem in showing the actual items of combination of the inputted...

to make it more easy to understand...

for example

the user input " apple banana cherry mango orange"

number of takes at a time: " 3 "

the output will show the formula and computation and the total number of combinations:

for example the answer is " 10 "

now here comes the problem.

i need to show the possible combinations of the items if the total combinations is less or equal to 10

apple banana cherry mango orange by taking 3 at a time

example

apple banana cherry

apple banana mango

apple banana orange

apple cherry mango

apple cherry orange

apple mango orange

banana cherry mango

banana cherry orange

banana mango orange

cherry mango orange

thank you in advance guys

posted 4 years ago

Kaisen,

First: I broke up those two enormous lines of yours. For starters, they screw up the window formatting here; and secondly they're a very bad coding habit. Please re-read the UseCodeTags (←click) page

Second: Please KeepItDown (←click). Using all caps (as above) is regarded as

Third: As to your actual problem, there are several ways to tackle it; just one of which is to use recursion, viz:

"3 from 10" == 1 + all combinations of "2 from the remaining 9", which in turn == 1 + "1 from the remaining 8".

Winston

kaisen adina wrote:THANK YOU IN ADVANCE HOPE YOU CAN HELP ME...

Kaisen,

First: I broke up those two enormous lines of yours. For starters, they screw up the window formatting here; and secondly they're a very bad coding habit. Please re-read the UseCodeTags (←click) page

*thoroughly*.

Second: Please KeepItDown (←click). Using all caps (as above) is regarded as

**SHOUTING!!!**and it's not pleasant to read.

Third: As to your actual problem, there are several ways to tackle it; just one of which is to use recursion, viz:

"3 from 10" == 1 + all combinations of "2 from the remaining 9", which in turn == 1 + "1 from the remaining 8".

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

Campbell Ritchie

Sheriff

Posts: 53747

127

kaisen adina

Greenhorn

Posts: 2

posted 4 years ago

i'm finished at calculating the combinations there are

but the problem sir is that

when the total combinations entered by the user is <=10

it will print all the 10 combinations of the items or objects entered by the user...

the hard part is that is the "number of takes at a time"

for example if the user input 2 as a number of takes at a time it should print only 2 colums

if the user input 3 as a number of takes it should look like as the example above...

and so on...

Campbell Ritchie wrote:Are you supposed to calculate how many combinations there are, or print them all out?

i'm finished at calculating the combinations there are

but the problem sir is that

when the total combinations entered by the user is <=10

it will print all the 10 combinations of the items or objects entered by the user...

the hard part is that is the "number of takes at a time"

for example if the user input 2 as a number of takes at a time it should print only 2 colums

if the user input 3 as a number of takes it should look like as the example above...

and so on...

It is sorta covered in the JavaRanch Style Guide. |