+ 1

Почему не работает итератор

Вот код: import java.util.*; public class Bowling { HashMap<String, Integer> players; Bowling() { players = new HashMap<String, Integer>(); } public void addPlayer(String name, int p) { players.put(name, p); } //введите код сюда public String getWinner(){ Iterator<String> it = players.iterator(); String res; return res; } } public class Program { public static void main(String[ ] args) { Bowling game = new Bowling(); Scanner sc = new Scanner(System.in); for(int i=0;i<3;i++) { String input = sc.nextLine(); String[] values = input.split(" "); String name = values[0]; int points = Integer.parseInt(values[1]); game.addPlayer(name, points); } game.getWinner(); } }

1st Dec 2021, 5:24 AM
Владислав Пономарёв
Владислав Пономарёв - avatar
1 ответ
+ 1
HashMap is not Collection, but Set is var it = players.entrySet().iterator(); // where iterator is type: Iterator<Map.Entry<String, Integer>> it
1st Dec 2021, 9:24 AM
zemiak