Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Please Help!!Daughter needs help with java code

Reply
Thread Tools

Please Help!!Daughter needs help with java code

 
 
Miggy23@gmail.com
Guest
Posts: n/a
 
      12-01-2005
Hello everyone,

I apologize for taking up anyone's time with such a newbie question.
However, my daughter is tearing her hair out over this code. I myself
don't know anything about programming however, being the father that I
am, I am hoping that someone can respond to my plea for help and
provide her with a solution. Below is her code. Thank you all and God
Bless!!

Problem: Print out all the 4 number combinations using only the
following numbers: 6, 9,0,3,1

The code is giving her only 5 combinations at the moment. This is
where she needs help.

//Source code//

import java.math.BigInteger;


public class NumGen {
public static void main(String[] args) {
char[] elements = {'6', '9', '0', '3', '1'};
int[] indices;
CombinationGenerator x = new CombinationGenerator (elements.length,
4);
StringBuffer combination;

while (x.hasMore ()) {
combination = new StringBuffer ();
indices = x.getNext ();
for (int i = 0; i < indices.length; i++) {
combination.append (elements[indices[i]]);
}
System.out.println (combination.toString ());
}

}
}

 
Reply With Quote
 
 
 
 
Oliver Wong
Guest
Posts: n/a
 
      12-01-2005
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>
> Problem: Print out all the 4 number combinations using only the
> following numbers: 6, 9,0,3,1


The problem statement is not clear to me. Is it asking for all strings
of length 4 whose alphabet is {6, 9, 0, 3, 1}? Or is it asking to print all
permutations of the set {6,9,0,3,1}, except don't print the last character?
Or something else?

Here's a legal string from the first interpretation which is not legal
in the second interpretation, in case the difference isn't clear: 0000.

- Oliver


 
Reply With Quote
 
 
 
 
cbroussard@liquiddatainc.com
Guest
Posts: n/a
 
      12-01-2005
You also did not paste an additional class file CombinationGenerator.
Also what's the purpose this class??


http://www.binaryfrost.com

 
Reply With Quote
 
Daniel Dyer
Guest
Posts: n/a
 
      12-01-2005
On Thu, 01 Dec 2005 22:25:26 -0000, <(E-Mail Removed)> wrote:

> You also did not paste an additional class file CombinationGenerator.
> Also what's the purpose this class??
>


It's almost certainly this class (or something very similar)

http://www.merriampark.com/comb.htm

I stumbled across it myself a few weeks back when looking for some code to
generate combinations. The algorithm is sound but I modified it to work
with longs rather than BigIntegers since I didn't need to work with big
sets and I used generics to get it actually generate the combinations as
arrays of the appropriate type rather than just an int array of indices.

Dan.

--
Daniel Dyer
http://www.dandyer.co.uk
 
Reply With Quote
 
Miggy23@gmail.com
Guest
Posts: n/a
 
      12-01-2005
Sorry for the confusion everyone. I am trying my best to be clear.
She is trying to print out all the possible number combinations of
length 4 using only the following numbers: 6,9,0,3, and 1.

 
Reply With Quote
 
Miggy23@gmail.com
Guest
Posts: n/a
 
      12-01-2005
Daniel,

Thanks for the link, however, how would she modify the code to only do
9,6,3,0,1 instead of alphabets of length 4?

 
Reply With Quote
 
frankgerlach@gmail.com
Guest
Posts: n/a
 
      12-01-2005
I guess someone is trying to get his homework done by using the usenet
)

 
Reply With Quote
 
Miggy23@gmail.com
Guest
Posts: n/a
 
      12-01-2005
Thanks for the reply Oliver. Sorry for the confusion. She is trying
to find all strings of length 4 whose alphabet is {6,9,0,3,1). In
other words, find all the possible number combinations for {6,9,0,3,1)
of lenght 4. Sorry if I am still not clear. I'm not a programmer.

Thank you all for your help!!

 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-01-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Sorry for the confusion everyone. I am trying my best to be clear.
> She is trying to print out all the possible number combinations of
> length 4 using only the following numbers: 6,9,0,3, and 1.
>


To me, there is no new information in this post with respect to your
original one.

Here's what I understand (and have understood since the first post):

The strings are of length 4.
Using characters other than 6, 9, 0, 3, 1 is not permitted.
You want ALL such strings.

Here's what's unclear (and was unclear since the first post):

Can the characters repeat? E.g. is 0000 a legal string?
Is the fact that the numbers not in any discernable order of some
significance? I.e. why didn't you say "0,1,3,6,9"?
Why is BigInteger getting involved for such small integers?
What is CombinationGenerator? Or more importantly, where did it come
from? You daughter? The teacher? Somewhere else?

- Oliver


 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      12-01-2005

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Thanks for the reply Oliver. Sorry for the confusion. She is trying
> to find all strings of length 4 whose alphabet is {6,9,0,3,1). In
> other words, find all the possible number combinations for {6,9,0,3,1)
> of lenght 4. Sorry if I am still not clear. I'm not a programmer.
>
> Thank you all for your help!!


Does she know what recursion is?

- Oliver


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VERY Urgent Direct Client Needs : 9 JAVA/J2EE (core JAVA) must hv expon Finance indstry. sarah Fernandes Java 0 03-09-2011 05:16 PM
Please please please help this guy with his open source java app casioculture@gmail.com Java 4 05-05-2005 08:24 AM
PIX to Cisco 1721 IPSec Tunnel NEEDS some DRAINO, PLEASE HELP! Cisco 5 01-30-2005 04:06 AM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments