Advertisement
Boyan5

Untitled

Apr 20th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. import java.text.MessageFormat;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4.  
  5. public class QASADS {
  6. public static void main(String[] args){
  7. HashMap<String,Double> MyDictionary = new HashMap<>( 6);
  8.  
  9.  
  10. MyDictionary.put("Николай", 3.00);
  11. MyDictionary.put("Нина", 4.50);
  12. MyDictionary.put("Сжетослав", 5.50);
  13. MyDictionary.put("Стефан", 3.50);
  14. MyDictionary.put("Христо", 4.00);
  15. MyDictionary.put("Юлиaн", 6.00);
  16.  
  17.  
  18. System.out.println("HashMap Size : " + MyDictionary.size());
  19.  
  20.  
  21.  
  22. Double tsanevMark = MyDictionary.get("Tsanev");
  23. System.out.printf("Tsanev's mark: %.2f %n", tsanevMark);
  24.  
  25. System.out.println(MessageFormat.format("Tsanev''s mark: {0,number,#.##}", tsanevMark));
  26.  
  27.  
  28.  
  29. MyDictionary.remove("Светослав");
  30. System.out.println("Светослав removed.");
  31.  
  32.  
  33. System.out.printf("Is Tsanev in the hash table: %b %n", MyDictionary.containsKey("Светослав"));
  34.  
  35. System.out.printf("Is Tsanev in the hash table: %b %n", MyDictionary.containsValue(6.00));
  36.  
  37.  
  38.  
  39. MyDictionary.put("Nerdy", 3.25);
  40. System.out.println("Nerdy's mark changed.");
  41.  
  42.  
  43. System.out.println("Students and marks:");
  44.  
  45. for (Map.Entry<String, Double> items : MyDictionary.entrySet()) {
  46.  
  47. System.out.printf("Student %s has %.2f%n", items.getKey(), items.getValue());
  48. }
  49.  
  50.  
  51. System.out.printf("There are %d students.%n", MyDictionary.size());
  52. MyDictionary.clear();
  53. System.out.println("Students hashmap cleared.");
  54. System.out.printf("Is hash table empty: %b%n", MyDictionary.isEmpty());
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement