Quiz Space

Programming Concepts using Java · Quiz 2 · 4 Aug 2024 · May 2024 term

Question 13: Consider the Java code given below. What will the output…

Question 13

+7 marksOne correct option

Consider the Java code given below.

java
import java.util.*;
public class MapTest {
public static void printPlayers(Map<String, Integer> m) {
var map1 = new LinkedHashMap<String, Integer>();
var map2 = new TreeMap<String, Integer>();
String[] players = {"Virat", "Rohit", "Rahul"};
for (String p : players) {
if (m.containsKey(p)) {
map1.put(p, m.get(p));
map2.put(p, m.get(p));
} else {
map1.put(p, 0);
map2.put(p, 0);
}
}
System.out.println(map1);
System.out.println(map2);
}
public static void main(String[] args) {
var map = new HashMap<String, Integer>();
map.put("Rohit", 45);
map.put("Rahul", 60);
map.put("Virat", 100);
map.put("Pant", 32);
printPlayers(map);
}
}

What will the output be?

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 13 of 15 in the IIT Madras BS Programming Concepts using Java (Java) Quiz 2 paper sat on 4 Aug 2024, in the May 2024 term (IIT M DIPLOMA AN EXAM QDD2 4 Aug 2024). It carries 7 marks.

More questions from this paper

  1. Q1Consider the Java code given below. The method boolean containsKey (Object key) in the class Map returns true if and on…
  2. Q2Consider two Java files located in two different packages as shown below. Vehicle.java: Car.java Choose the correct opt…
  3. Q3Consider the Java code given below. Choose the correct option when the program is executed as:\ java -ea Test
  4. Q4Consider the Java code given below. Choose the correct option.
  5. Q5Consider the Java code given below. Choose the correct option(s) to fill in place of CODE BLOCK so that the output is:\…
  6. Q6Consider the Java code given below. What will the output be?
  7. Q7Consider the Java code given below. What will the output be?
  8. Q8Consider the Java code given below. Identify the appropriate option to fill in place of LINE X such that the output is:…
  9. Q9Consider the Java code given below. After type erasure, which of the following correctly represents the ArrayOperations…
  10. Q10Consider the Java code given below. Choose the correct option.
  11. Q11Consider the Java code given below. Choose the correct option to be filled in place of LINE 1 so that the output is:\ […
  12. Q12From among the options, choose the code segment that gives the same output as is given by the Java code inside the CODE…
  13. Q14Consider the Java code given below. Identify the appropriate option to fill in place of LINE X such that the output is:…
  14. Q15Consider the Java code given below that prints the most impressive act among a set of given Performer objects. From amo…