Page Contents

## Interview Content

- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions

# Program in Java to find the missing number in a second array

**Ans: **

In this tutorial, you will learn how to write Java program to find the missing number in second array.

This program is very simple and easy. As we have fixed array so we are not going to take any array input from the user.

Just execute the program and you will find the missing element in the second array which is available in first array.

Our Logic behind this program is:

- We have already two array arr1 with elements 1, 2, 3, 4, and 5.
- arr2 with elements 2, 3, 1, 0, and 5.
- We will add the all elements of arr1 together.
- Similarly for arr2 we will add it.
- And at last we will subtract arr1 elements sum with arr2.
- And we will get the missing number of arr2.

## How our program will behave?

Our program have already two array arr1 and arr2.

arr1 have 1, 2, 3, 4, 5 elements and arr2 have 2,3,1,0,5 elements.

So it should print 4 in output as in second array 4 is missing which is in array first.

## Java Program to find missing number in second array which is in first array.

```
public class Main {
public static void main(String[] args) {
int sum = 0;
int arr1[]={1,2,3,4,5};
int arr2[]={2,3,1,0,5};
int size=arr1.length;
for(int i=0;i<size;i++){
sum=sum+arr1[i]-arr2[i];
}
System.out.println("missing number is = " +sum);
}
}
```

**Output:**

## Also prepare these Java Programs:

- Write a program in Java to print the Fibonacci series using iterative method.
- Palindrome program in Java using Iterative method
- Java program to find largest of three numbers
- Java program to sum the digits of a number using recursion
- Java program to swap two numbers using third variable
- Java Program to check if two strings are anagrams
- Java program to find largest and smallest number in an array
- Java Program to find top two maximum number in array
- Java Program to remove duplicate elements from an array

##### Latest Uploads on Website

- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program