0

I need to create a method that will compare two sets of integers and return a new set of integers that represent all matching numbers.

I am using a Random number generator that will for example generate 6 numbers eg.[12,33,28,17,45, 32].

In my console while using Scanner Class I will type in 6 numbers e.g. [32,5,11,12,43,1].

I need my method to return all matching numbers which in this case would be [12,32]

I want to use a set to achieve this. This is what I have so far.

 public Set<Integer> playNumbers (Set<Integer> GenNumbers, Set<Integer> myNumbers)
  {
    return null;
  }

GenNumbers the lottery numbers that were randomly generated. myNumbers my picked numbers that were typed in the console. return as set of matched numbers.

Not sure how to proceed with this.

user2246674
  • 7,621
  • 25
  • 28
cw.prime
  • 499
  • 4
  • 10
  • 16
  • 4
    The task is also known as: "Find the intersection of two sets of numbers". Using the term "intersect" will likely lead to finding some related questions. In any case, to do it manually (such as for homework), use a loop and the [`Set#contains`](http://docs.oracle.com/javase/6/docs/api/java/util/Set.html#contains(java.lang.Object) method. – user2246674 Sep 18 '13 at 21:01
  • See http://stackoverflow.com/questions/15931427/using-union-and-intersection-method-in-a-hashset , http://stackoverflow.com/questions/4349369/list-intersection-in-java , http://stackoverflow.com/questions/5283047/intersection-union-of-arraylists-in-java for some hints/approaches – user2246674 Sep 18 '13 at 21:05

0 Answers0