Maximum finding

Report a typo

Write a program to accept an integer n and to input n key and value pairs. Print the value of maximum key.

Sample Input 1:

2
0 2
5 4

Sample Output 1:

4
Write 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);
}
}
___

Create a free account to access the full topic