Write a program that accepts an array of integers and uses a HashMap to find the duplicates in the array. The program must print out the duplicate elements in ascending order.
Introduction to HashMap
Print Duplicates
Report a typo
Sample Input 1:
8
1 2 3 4 5 1 2 3Sample Output 1:
1 2 3Write a program in Java 17
import java.util.HashMap;
import java.util.Scanner;
class Main {
private static void printDuplicate(int[] map) {
// Enter your Code Here
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int [] map = new int[n];
for (int i = 0; i < n; ++i) {
map[i] = scanner.nextInt();
}
printDuplicate(map);
}
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.