Re: Discrete Math Question

Sorry man. your question doesn't make any sense whatsoever. you're having trouble saving the user input? As in write to a file or simply storing it in a variable within your program? And using WHAT bit strings exactly? You are going to need to be a bit more specific.

Re: Discrete Math Question

Have a look at the BitSet class.

kind regards,

Jos

Re: Discrete Math Question

Unfortunately, I am not allowed to use the bitSet class, otherwise it would have been easy. Basically, I need to get two sets. The Universal set is {0-9}, as I mentioned. So lets say user wants set A {0,1,2} and set B {3,4,5}. The problem I have is how to prompt the user to enter the data, as the sets can be empty, or can contain 5,6,7 elements. That is what I am having trouble figuring out. I hope this is more specific. Should I just use a do while loop for this?

Re: Discrete Math Question

Lets do it the other way around: what *are* you allowed to use? Does it really have to be a crippled solution?

kind regards,

Jos

Re: Discrete Math Question

I am allowed to use bit strings to convert the user input into 0s (if element is not in set) and 1s (if element is in set) for the sets. That is basically what the program is about, and then I am supposed to print out some operations on the sets.I have no trouble performing those, I am stumped on gathering input for both sets and then converting them to 0s and 1s and storing the sets. So if the set is {0,1,2}, there are 1s in those spaces and 0s anywhere else.

Re: Discrete Math Question

The following code scans a String for 0s and 1s:

Code:

`for (int i= 0; i < yourString.length(); i++) {`

if (yourString.charAt(i) == '0')

// a 0 was found at position i

else if (yourString.charAt(i) == '1')

// a 1 was found at position i

}

kind regards,

Jos

Re: Discrete Math Question

Re: Discrete Math Question

Quote:

Originally Posted by

**sunde887** I like your new sig Jos!

:-D

kind regards,

Jos

Re: Discrete Math Question

Quote:

Originally Posted by

**JosAH** The following code scans a String for 0s and 1s:

Code:

`for (int i= 0; i < yourString.length(); i++) {`

if (yourString.charAt(i) == '0')

// a 0 was found at position i

else if (yourString.charAt(i) == '1')

// a 1 was found at position i

}

kind regards,

Jos

Thanks a lot, that helps, but I did it without strings, I just used this block of code :

Code:

` while ((userChoice != -1) && in.hasNextInt())`

{

userChoice = in.nextInt();

if ((userChoice > -1) && (userChoice < 10))

{

setA |= (1 << userChoice);

System.out.print ("Enter a number between 0 and 9 (or -1 to end): ");

}

}

I figured it out, but I appreciate the help :)