I´m getting "null" and not the number "0"... I have tried so many times now, and it has to do with if statement "map.put(x, 1)"
input:
Lily
Charlie
Mia
Jacob
Sophia
Alfie
Isabella
Freddie
Grace
Oscar
output:
a 9
b 2
c 4
d 2
e 6
f 2
g 1
h 2
i 7
j 1
k null
l 6
m 1
n null
o 3
p 1
q null
r 4
s 3
t null
u null
v null
w null
x null
y 1
z null
package com.codegym.task.task10.task1012;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Number of letters
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// Alphabet
String abc = "abcdefghijklmnopqrstuvwxyz";
char[] abcArray = abc.toCharArray();
ArrayList<Character> alphabet = new ArrayList<>();
for (char letter : abcArray) {
alphabet.add(letter);
}
// Read in strings
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < 10; i++) {
String s = reader.readLine();
list.add(s.toLowerCase());
}
// write your code here
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < list.size(); i++) {
String s = list.get(i);
for (char x : s.toCharArray()) {
if (!map.containsKey(x)) {
map.put(x, 1);
}else {
map.put(x, map.get(x) + 1);
}
}
}
for (char x : abcArray) {
System.out.println(x + " " + map.get(x));
}
}
}