Write a program to accept an integer n and to input n key and value pairs. Print the value of maximum key.
Introduction to HashMap
Maximum finding
Report a typo
Sample Input 1:
2
0 2
5 4Sample Output 1:
4Write a program in Java 17
import java.util.HashMap;
import java.util.Scanner;
class Main {
private static void printMaxKey(HashMap<Integer, Integer> map) {
// implement me
}
public static void main(String[] args) {
HashMap<Integer, Integer> map = new HashMap<>();
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
for (int i = 0; i < n; ++i) {
map.put(scanner.nextInt(), scanner.nextInt());
}
printMaxKey(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.