Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: please tell me the code of union and intersection of two arrays without using collections

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default please tell me the code of union and intersection of two arrays without using collections

    I have searched on internet but did not find something useful. I do not want to use collections. please help me out!
    here's what i have written
    class ArrayDemo3
    {
    	static void union(int x[], int y[])
    	{
    		System.out.println("Union Elements:");
    		for(int i=0; i<x.length; i++)
    		{
    			for(int j=0; j<y.length; j++)
    			{
    				if(x[i]!=y[j])
    				System.out.println(x[i]);
    				//else 
     
    			}
    		}
    	}
    	static void intersection(int x[],int y[])
    	{
    		System.out.println("Intersection Elements:");
    		for(int i=0; i<x.length; i++)
    		{
    			for(int j=0; j<y.length; j++)
    			{
    				if(x[i]==y[j])
    				System.out.println(x[i]);
    			}
    		}
    	}
     
    	public static void main(String... kl)
    	{
    		int p[]={2,5,7,8,5,1};
    		int q[]={5,8,2,0,1,6,3};
    		union(p,q);
    		intersection(p,q);
    	}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: please tell me the code of union and intersection of two arrays without using collections

    Before writing any code you need to decide what steps the code should take to do the job.
    Do you have a list of the steps the code needs to do?
    For union?
    For intersection?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Intersection and Union of Three or more Sets
    By robertm08 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 19th, 2013, 10:18 AM
  2. Intersection of two loops
    By sengreen in forum Loops & Control Statements
    Replies: 3
    Last Post: May 26th, 2013, 12:44 PM
  3. Union and Intersection methods (SetADT)
    By jason3460 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: May 7th, 2013, 11:22 AM
  4. INTERSECTION OF TWO LIST
    By muhammad waqar in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 5th, 2013, 08:09 AM
  5. [SOLVED] UNION OF TWO INTEGER ARRAYS... HELP?
    By Medo Almasry in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 23rd, 2011, 03:28 PM