Results 1 to 10 of 10
Thread: Discrete Math Question
- 01-15-2012, 08:45 AM #1
Member
- 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 {0-9}, 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! :)
- 01-15-2012, 12:31 PM #2
Member
- 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.
- 01-15-2012, 02:14 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Discrete Math Question
Have a look at the BitSet class.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-15-2012, 08:05 PM #4
Member
- 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 {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?
- 01-15-2012, 08:09 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-15-2012, 09:52 PM #6
Member
- 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.
- 01-16-2012, 06:30 AM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Discrete Math Question
The following code scans a String for 0s and 1s:
kind regards,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 }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-16-2012, 06:45 AM #8
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: Discrete Math Question
I like your new sig Jos!
- 01-16-2012, 07:25 AM #9
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 01-16-2012, 07:49 AM #10
Member
- 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 :
I figured it out, but I appreciate the help :)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: 08-06-2011, 04:05 PM -
Discrete Mathematics Question
By asafavi in forum New To JavaReplies: 3Last Post: 12-09-2010, 11:05 AM -
Create Math.sin without math.sin
By vudoo in forum New To JavaReplies: 11Last Post: 12-07-2010, 06:23 AM -
Math.random Question
By noble in forum New To JavaReplies: 21Last Post: 09-16-2010, 02:17 AM -
Math class question
By shendel in forum New To JavaReplies: 1Last Post: 03-05-2009, 12:06 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks