Results 1 to 8 of 8
Thread: Set of Integers
- 01-27-2010, 09:46 AM #1
Member
- Join Date
- Jan 2010
- Posts
- 23
- Rep Power
- 0
Set of Integers
Hello there! H0w can i make a java program using Queue that would print a set of Integers..for example; Union.,.
Qa = 123
Qb = 456
output = 123456
Intersection
Qa = 123
Bb = 135
output = 13
Cartesian
Qa = {1,2}
Qb = {3,4}
output = 1, 3, 1 ,4 ,2 ,3, 2, 4
I can't visualized this. Can somebody help me or just give me a sample program? Thank you.:)
- 01-27-2010, 10:03 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,717
- Rep Power
- 16
Why use a Queue to represent a set when a Set is available?
union==addAll() intersection==retainAll()
Cartesian products involve creating a new data type. If you are only printing the product and not manipulating it just use nested for loops.
- 01-27-2010, 12:38 PM #3
Member
- Join Date
- Jan 2010
- Posts
- 21
- Rep Power
- 0
Here is the answer for you
Here is the coding.... It may be useful to you.....
- 01-27-2010, 12:54 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
- 01-28-2010, 09:44 AM #5
Member
- Join Date
- Jan 2010
- Posts
- 23
- Rep Power
- 0
Oh, thank you for the code. Highly appreciated. But I have another one. How to implement an array using Queue? Thanks
- 01-28-2010, 09:51 AM #6
Member
- Join Date
- Jan 2010
- Posts
- 21
- Rep Power
- 0
Sorry..... I think this one is correct...
Hey .... Sorry i made a mistake.... Please check it out .... Here to remove the duplicates i use TreeSet....
- 01-28-2010, 10:07 AM #7
Member
- Join Date
- Jan 2010
- Posts
- 23
- Rep Power
- 0
Thank you again. But in my program I have 3 choices. 1.Union 2.Intersection. 3. Cartesian.
When I compiled the program the compiler would ask me the 3 choices. If I entered 1 it will switch to Union then I will input depend how many numbers I'd like to input. For ex: Qa is 123, Qb is 456. output is = 123456. But there is an exception. If entered the same element in the Queue u can display one. For ex: QA- 123, QB 234. Output = 1234..it cannot be 122334. Thank you so much. Appreciated it.
- 01-28-2010, 10:29 AM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,421
- Blog Entries
- 7
- Rep Power
- 26
Similar Threads
-
Sorting 3 Integers Using If Else
By MSteinman in forum New To JavaReplies: 12Last Post: 02-19-2010, 12:52 PM -
Integers and Lists
By TGH in forum New To JavaReplies: 8Last Post: 01-27-2010, 09:49 AM -
How to write integers into file?
By dj kourampies in forum New To JavaReplies: 1Last Post: 08-20-2009, 04:52 AM -
how to get the Integers out of a String
By JordashTalon in forum New To JavaReplies: 10Last Post: 01-30-2009, 06:28 PM -
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12-09-2007, 05:49 PM
Bookmarks