A class Mixer has been defined to merge two sorted integer arrays in ascending order.
Some of the members of the class are given below:
Data members/instance variables:
int arr[ ]:to store the elements of an array
int n:to store the size of the array
Member functions:
Mixer(int nn):constructor to assign n=nn
void accept():to accept the elements of the array in ascending order without any duplicates
Mixer mix(Mixer A) : to merge the current object array elements with the parameterized array elements and return the resultant object
void display():to display the elements of the array

Specify the class Mixer, giving details of the constructor(int), void accept( ), Mixer mix(Mixer) and void display() . Define the main() function to create an object and call the function accordingly to enable the task.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram


					import java.util.Scanner;
public class Mixer
    int arr[];
    int n;
    Scanner sc=new Scanner(System.in);

    Mixer(int nn)
        arr=new int[n];

    void accept()
        System.out.println("Enter "+n+" elements in ascending order");
        for(int i=0;i< n;i++)

    Mixer mix(Mixer A)
        Mixer B=new Mixer(n+A.n);		
        int x=0;
        for(int i=0;i< n;i++)
        for(int j=0;j< A.n;j++)
        return B;

    void display()
        for(int i=0;i< n;i++)
            System.out.print(arr[i]+" ");

    public static void main()
        Scanner sc1=new Scanner(System.in);
        System.out.println("ENTER SIZE OF FIRST ARRAY");
        int sizeOfFirstArray=sc1.nextInt();
        Mixer P=new Mixer(sizeOfFirstArray);
        System.out.println("ENTER SIZE OF SECOND ARRAY");
        int sizeOfSecondArray=sc1.nextInt();
        Mixer Q=new Mixer(sizeOfSecondArray);

        Mixer R=P.mix(Q);


Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *