Class 11 Class 12

Combine Two Arrays into One ISC 2012 Theory

A class Combine contains an array of integers which combines two arrays into a single array including the duplicate elements if any, and sorts the combined array. Some of the members of the class are given below:

Class name: Combine
Data members/instance variables:
com[]: integer array
size: size of the array
Member functions/methods:
Combine(int num): parameterized constructor to assign size = num.
void inputArray(): to accept the array elements.
void sort(): sorts the elements of combined array in ascending order using the selection sort technique.
void mix(Combine a, Combine b): combines the parameterized object arrays and stores the result in the current object array along with duplicate elements if any.
void display(): displays the array elements.

Specify the class Combine giving details of the constructor, void inputArray(). void sort(), void mix(Combine, Combine) and void display(). Also define the main() function to create an object and call the methods accordingly to enable the task.

class Combine{
    int com[];
    int size;
    public Combine(int num){
        size = num;
        com = new int[size];
    public void inputArray()throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        for(int i = 0; i < size; i++)
            com[i] = Integer.parseInt(br.readLine());
    public void sort(){
        for(int i = 0; i < size; i++){
            int small = com[i];
            int pos = i;
            for(int j = i + 1; j < size; j++){ if(small > com[j]){
                    small = com[j];
                    pos = j;
            int temp = com[i];
            com[i] = small;
            com[pos] = temp;
    public void mix(Combine a, Combine b){
        int index = 0;
        for(int i = 0; i < a.size; i++)
  [index++] =[i];
        for(int i = 0; i < b.size; i++)
  [index++] =[i];
    public void display(){
        for(int i = 0; i < size; i++)
            System.out.print(com[i] + "\t");
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        System.out.print("First array size: ");
        int size1 = Integer.parseInt(br.readLine());
        System.out.print("Second array size: ");
        int size2 = Integer.parseInt(br.readLine());
        Combine obj1 = new Combine(size1);
        Combine obj2 = new Combine(size2);
        Combine obj3 = new Combine(size1 + size2);
        System.out.println("Enter first array elements:");
        System.out.println("Enter second array elements:");
        System.out.println("First array elements:");
        System.out.println("Second array elements:");
        obj3.mix(obj1, obj2);
        System.out.println("Combined array:");

8 replies on “Combine Two Arrays into One ISC 2012 Theory”

String s = Integer.toString(num);
The above method doesn’t depend on Scanner class. It can be used in any input method.

Just use Integer.parseInt() for this purpose, whether you’re using Scanner class or any other class.

Sir,a program is given which states that:
WAP in java to accept an integer number. Now create a new number by all the alternate digits of the original number.
Sample Input:
Sample Output:

Here is the link to the solution of the problem to generate a new integer using alternate digits of a number.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.