Results 1 to 10 of 10
Thread: Discrete Math Question
 01152012, 09:45 AM #1Member
 Join Date
 Jan 2012
 Posts
 7
 Rep Power
 0
Discrete Math Question
Hello all,
I need to write a program for my computing math course ,and I am kind of stumped by the assignment. Basically, I am given the universal set {09}, and need to ask the user to input set A and set B,and then find out what the sym.diff is, where they intersect and such, but without using the set classes in java, but rather using bit strings. I know how to write the part for where they intersect, but I am having trouble saving the user input for both sets and then using the bit strings. I know this is probably a stupid question, but I have wondered about this for a while, and I still have trouble doing it.Any help will be greatly appreciated! :)
 01152012, 01:31 PM #2Member
 Join Date
 Oct 2011
 Posts
 92
 Rep Power
 0
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.
 01152012, 03:14 PM #3
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,999
 Blog Entries
 7
 Rep Power
 22
Re: Discrete Math Question
Have a look at the BitSet class.
kind regards,
JosI have the stamina of a seal; I lie on the beach instead of running on it.
 01152012, 09:05 PM #4Member
 Join Date
 Jan 2012
 Posts
 7
 Rep Power
 0
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 {09}, 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?
 01152012, 09:09 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,999
 Blog Entries
 7
 Rep Power
 22
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,
JosI have the stamina of a seal; I lie on the beach instead of running on it.
 01152012, 10:52 PM #6Member
 Join Date
 Jan 2012
 Posts
 7
 Rep Power
 0
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.
 01162012, 07:30 AM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,999
 Blog Entries
 7
 Rep Power
 22
Re: Discrete Math Question
The following code scans a String for 0s and 1s:
Java 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 }
JosI have the stamina of a seal; I lie on the beach instead of running on it.
 01162012, 07:45 AM #8
 Join Date
 Jan 2011
 Location
 Richmond, Virginia
 Posts
 3,069
 Blog Entries
 3
 Rep Power
 9
Re: Discrete Math Question
I like your new sig Jos!
 01162012, 08:25 AM #9
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,999
 Blog Entries
 7
 Rep Power
 22
 01162012, 08:49 AM #10Member
 Join Date
 Jan 2012
 Posts
 7
 Rep Power
 0
Re: Discrete Math Question
Thanks a lot, that helps, but I did it without strings, I just used this block of code :
Java 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): "); } }
Similar Threads

math and GUI
By urbanleg in forum AWT / SwingReplies: 3Last Post: 08062011, 04:05 PM 
Discrete Mathematics Question
By asafavi in forum New To JavaReplies: 3Last Post: 12092010, 12:05 PM 
Create Math.sin without math.sin
By vudoo in forum New To JavaReplies: 11Last Post: 12072010, 07:23 AM 
Math.random Question
By noble in forum New To JavaReplies: 21Last Post: 09162010, 02:17 AM 
Math class question
By shendel in forum New To JavaReplies: 1Last Post: 03052009, 01:06 PM
Bookmarks