fork download
  1. import java.util.*;
  2.  
  3. class Hero {
  4. private String name;
  5. public Hero(String name) {
  6. this.name = name;
  7. }
  8. public String getName() {
  9. return this.name;
  10. }
  11. }
  12.  
  13. class Renshu3_3 {
  14. public static void main(String[] args) {
  15. Hero h1 = new Hero("斎藤");
  16. Hero h2 = new Hero("鈴木");
  17. Map<Hero, Integer> hmap = new HashMap<Hero, Integer>();
  18. hmap.put(h1, 3);
  19. hmap.put(h2, 7);
  20. for(Hero key : hmap.keySet()) {
  21. Integer value = hmap.get(key);
  22. System.out.println(key.getName() + "が倒した敵の数=" + value);
  23. }
  24. }
  25. }
Success #stdin #stdout 0.06s 27868KB
stdin
Standard input is empty
stdout
斎藤が倒した敵の数=3
鈴木が倒した敵の数=7