The program code for the question described:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
public class Test {
public static ArrayList findMissing(int[] input) {
List<Integer> result = IntStream.rangeClosed(1, input.length).boxed().collect(Collectors.toList());
result.removeAll((IntStream.of(input).boxed().collect(Collectors.toList())));
return (ArrayList) result;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter number of elements for the array: ");
int n = scanner.nextInt();
int[] array = new int[n];
System.out.println("Enter elements of the array: ");
for (int i = 0; i < array.length; i++) {
array[i] = Integer.valueOf(scanner.next());
}
System.out.println("Missing elements: ");
System.out.println(Arrays.toString(findMissing(array).toArray()));
}
}
The ouput was:
Enter number of elements for the array:
6
Enter elements of the array:
1 1 2 6 3 5
Missing elements:
[4]