Old task: Read pairs (a number and string) from the keyboard, and then display them on the screen. New task: Read the same pairs from the keyboard and store them in a HashMap. Any empty input string signifies the end of data entry. The numbers can be repeated, but not the strings. The entered data must not be lost! Then the program should display the contents of the HashMap on the screen, each pair on a new line.
Functionality is not enough!
- 12
Locked
Comments (22)
- Popular
- New
- Old
You must be signed in to leave a comment
DJ Stanhope
10 August 2021, 03:57
Conditions say any empty input signals the end of data entry, and yet in order to get the task to validate successfully I had to make it so it would continue collecting data if the name field was empty. Makes no sense.
0
remote87
20 January 2021, 13:23

0
John Squirrels Website Admin at CodeGym
21 January 2021, 11:09
What task exactly do you refer to?
0
Gellert Varga
10 February 2021, 20:57
You got an NullPointerException in line 21, but just that line is unreadable on that screenshot.
I would like to look that line:) and the whole prog.
0
HollyTi
31 October 2020, 22:55
My solution failed at Req.3: In the main method, declare a HashMap variable and immediately initialize it,
because it had:
Map<String, Integer> map = new HashMap<>();
It passed with:
HashMap<String, Integer> map = new HashMap<String, Integer>();
Lol, always did it my way, never failed before, as it wasn't a requirement :)
+1
Je
23 October 2020, 14:45
I discovered computeIfPresent in this hashmap exercise. hope you'll find it useful too.
0
Pavel Naumovich
11 October 2020, 12:29
Hashmap keys must be unique, use string as keys and int as values, when displaying content of your hashmap , no particular order is required
0
George
10 October 2020, 21:17
somehow I got the impression that the "empty input" condition had to do with exceptions since there's no null integer and I didn't want to split the one liner that was already there. Got it right on 1st try with try-catch but it seems this was irrelevant. I'm not even sure why this task was set to "Hard". It was a simple input and hashmap condition.
0
Baurzhan Konurbayev
2 August 2020, 00:46
Output in different order doesn't count as a solution.
For example,
But it's not one of the requirements 0
Petros
30 July 2020, 20:52
Keys are unique, values aren't. In this problem Strings are keys and integers are values. Flew over my head so took me a while to solve this.
0
Lucas Hoage
7 June 2020, 20:27
Nothing has to be in order.
Your output should look like:
int string
int string
int string
or
int
int string
int string
+1
Patrick Moreland
15 March 2020, 03:04
I beat my head against a brick wall on this one for hours. I rewrote the entire thing three or four times, and went down many paths of trying to make it tolerant of all sorts of unexpected patterns of data entry. All of that was a waste of time. In the end, the issue had to do with an unexplained difference between how the online code entry handles String.isEmpty() vs. Intellij IDEA. I was only able to get this to pass using IntelliJ. Very frustrating.
0