Hi,
Please could anyone tell me why the fourth condition fails. I do not see the error and as far as i understand my code takes 10 pairs from the console and adds them to a hashmap.
Best Regards
Steffen
package de.codegym.task.task10.task1018;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
/*
Korrekturen sind nötig
*/
public class Solution {
HashMap<Integer, String> map;
static Integer index;
static String name;
public Solution() {
this.map = new HashMap<Integer, String>();
map.put(index, name);
}
public static void main(String[] args) throws IOException {
Solution solution = new Solution();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < 10; i++) {
int index = Integer.parseInt(reader.readLine());
if(Debug.debug){
System.out.println("index = " + index);
}
String name = (String) reader.readLine();
if(Debug.debug){
System.out.println("name = " + name);
}
solution.map.put(index,name);
}
for (Map.Entry<Integer, String> paar : solution.map.entrySet()) {
index = paar.getKey();
name = paar.getValue();
if((index == null) || (name == null)){
continue;
}
System.out.println("Id=" + index + " Name=" + name);
}
}
public static class Debug{
public static boolean debug = false;
}
}