Home » Arrays(Dont Mess With Me) » Missing Number

Missing Number

import java.util.*;;
class rand extends Random
 public int generate()
 return nextInt(10);
public class Missingnum {
 public static void main(String args[])
 int i;
 int [] a= new int[10];
 rand r1 = new rand();
 HashSet h1= new HashSet ();
 HashSet h2= new HashSet ();

 for (i=0;i<10;i++)

 h1.add(a[i]);//removes duplicate elements.
 System.out.println("HashSet contains"+ h1);

 if(!h1.contains(i))//add all elements which are not in h1 to h2.

 System.out.println("Numbers not in HashSet"+h2);

 if(!h1.contains(i))//add remaining elements to h1

 System.out.println("Numbers now in HashSet H1"+h1);

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: