Jak sprawdzam w Intellij to wyświetla mi jak w zadaniu. Podpowiada mi, że liczba się nie wyświetla jeśli nie było ciągu (spacja po liczbie). Jednak jak sprawdzam to wygląda wszystko ok.
package pl.codegym.task.task10.task1019;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/*
Funkcjonalność to nie wszystko!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
HashMap<String, Integer> map= new HashMap<>();
String x;
int y=0,k=0;
String temp;
while (true)
{
x = reader.readLine();
if(x.equals("")){
break;
}
if(k==0)
{
y = Integer.parseInt(x);
k++;
System.out.println("Liczba " + y);
}
else
{
if(!x.equals(""))
{
temp = x;
try
{
map.put(temp,y);
System.out.println("map.put " + temp + " " + y);
}
catch (Exception e)
{
break;
}
k=0;
}
}
}
if(x.equals(""))
{
if(!map.containsValue(y))
{
map.put("",y);
}
}
for(Map.Entry<String, Integer> para: map.entrySet())
{
System.out.println(para.getValue() + " " + para.getKey());
}
}
}