Results 1 to 8 of 8
Thread: Set of Integers
 01272010, 10:46 AM #1Member
 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.:)
 01272010, 11:03 AM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,712
 Rep Power
 14
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.
 01272010, 01:38 PM #3Member
 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.....
 01272010, 01:54 PM #4
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,325
 Blog Entries
 7
 Rep Power
 25
 01282010, 10:44 AM #5Member
 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
 01282010, 10:51 AM #6Member
 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....
 01282010, 11:07 AM #7Member
 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.
 01282010, 11:29 AM #8
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,325
 Blog Entries
 7
 Rep Power
 25
Similar Threads

Sorting 3 Integers Using If Else
By MSteinman in forum New To JavaReplies: 12Last Post: 02192010, 01:52 PM 
Integers and Lists
By TGH in forum New To JavaReplies: 8Last Post: 01272010, 10:49 AM 
How to write integers into file?
By dj kourampies in forum New To JavaReplies: 1Last Post: 08202009, 04:52 AM 
how to get the Integers out of a String
By JordashTalon in forum New To JavaReplies: 10Last Post: 01302009, 07:28 PM 
Random Integers
By www.kwalski.com in forum Java AppletsReplies: 8Last Post: 12092007, 06:49 PM
Bookmarks