多选题 You need to update a value of a hash table (that is, HashMap) where the primary key must equal a specified string. Which statements would you need to use in the implementation of this algorithm?
  • A. Iteration statement
  • B. Expression statement
  • C. Conditional statement
  • D. Transfer of control statement
【正确答案】 A、B、C
【答案解析】迭代、表达式和条件语句可以用来实现该算法。下面的代码段演示了通过编程使用这些语句来替换一个人左手小指上的戒指。这些语句的前面具有标识它们类型的注释。 import java.util.HashMap; public class HashMapExample { public static void main(String[] args) { HashMap <String, String> leftHand = new HashMap <String, String> (); leftHand.put("Thumb", null); leftHand.put("Index finger", "Puzzle Ring"); leftHand.put("Middle finger", null); leftHand.put("Ring finger", "Engagement Ring"); leftHand.put("Little finger", "Pinky Ring"); // 迭代语句 for(String s : leftHand.keySet()) { // 条件语句 if(s.equals("Little finger")) { System.out.println(s + "had a" + leftHand.get(s)); // 表达式语句 leftHand.put("Little finger", "Engineer's Ring"); System.out.println(s + "has an" + leftHand.get(s)); } } } } $ Little finger had a Pinky Ring $ Little finger has an Engineer's Ring D不正确。在这个算法中没有控制转换语句。