Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
TreeMap<int, double> rates = new TreeMap<>();
rates.put(1, 6.5);
System.out.println(rates);
}
}
- A TreeMap cannot store numbers
- B Type arguments must be reference types: use TreeMap<Integer, Double>, and autoboxing converts the values Correct
- C rates needs a Comparator
- D 6.5 must be 6.5f
Correct Answer: Option B
javac: "unexpected type – required: reference, found: int".
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!