Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.MessageFormat;
- import java.util.HashMap;
- import java.util.Map;
- public class QASADS {
- public static void main(String[] args){
- HashMap<String,Double> MyDictionary = new HashMap<>( 6);
- MyDictionary.put("Николай", 3.00);
- MyDictionary.put("Нина", 4.50);
- MyDictionary.put("Сжетослав", 5.50);
- MyDictionary.put("Стефан", 3.50);
- MyDictionary.put("Христо", 4.00);
- MyDictionary.put("Юлиaн", 6.00);
- System.out.println("HashMap Size : " + MyDictionary.size());
- Double tsanevMark = MyDictionary.get("Tsanev");
- System.out.printf("Tsanev's mark: %.2f %n", tsanevMark);
- System.out.println(MessageFormat.format("Tsanev''s mark: {0,number,#.##}", tsanevMark));
- MyDictionary.remove("Светослав");
- System.out.println("Светослав removed.");
- System.out.printf("Is Tsanev in the hash table: %b %n", MyDictionary.containsKey("Светослав"));
- System.out.printf("Is Tsanev in the hash table: %b %n", MyDictionary.containsValue(6.00));
- MyDictionary.put("Nerdy", 3.25);
- System.out.println("Nerdy's mark changed.");
- System.out.println("Students and marks:");
- for (Map.Entry<String, Double> items : MyDictionary.entrySet()) {
- System.out.printf("Student %s has %.2f%n", items.getKey(), items.getValue());
- }
- System.out.printf("There are %d students.%n", MyDictionary.size());
- MyDictionary.clear();
- System.out.println("Students hashmap cleared.");
- System.out.printf("Is hash table empty: %b%n", MyDictionary.isEmpty());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement