как вариант, потому что буква "а" в конце списка. вот только я не пойму почему линкед хэшмап засунул первую бувку в самый зад 😯
package com.javarush.task.task10.task1012;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
/*
Количество букв
*/
public class Solution {
static int count = 0;
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
LinkedHashMap<String, Integer> mapa = new LinkedHashMap<>();
mapa.put("a",0);mapa.put("б",0);mapa.put("в",0);mapa.put("г",0);mapa.put("д",0);mapa.put("е",0);mapa.put("ё",0);
mapa.put("ж",0);mapa.put("з",0);mapa.put("и",0);mapa.put("й",0);mapa.put("к",0);mapa.put("л",0);mapa.put("м",0);mapa.put("н",0);
mapa.put("о",0);mapa.put("п",0);mapa.put("р",0);mapa.put("с",0);mapa.put("т",0);mapa.put("у",0);mapa.put("ф",0);
mapa.put("х",0);mapa.put("ц",0);mapa.put("ч",0);mapa.put("ш",0);mapa.put("щ",0);mapa.put("ъ",0);mapa.put("ы",0);
mapa.put("ь",0);mapa.put("э",0);mapa.put("ю",0);mapa.put("я",0);
List<Character> alphabet = Arrays.asList(
'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж',
'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о',
'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц',
'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я');
/* for (int i = 0; i < alphabet.size(); i++) {
mapa.put(alphabet.get(i).toString(), 0);
}*/
// Ввод строк
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
String line = reader.readLine();
list.add(line.toLowerCase());
}
for (String str:list){
for (int i = 0; i < alphabet.size(); i++) {
// i - a
for (int l = 0, y = str.length(); l < y; l++) {
char c = str.charAt(l);
if (alphabet.get(i) == c){
mapa.merge(alphabet.get(i).toString(),1, Integer::sum);
}
}
}
}
///тестики
mapa.remove("a");
for (Map.Entry<String, Integer> entry : mapa.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println(key + " " + value);
}
}
}
/*
for (int i = 0, n = str.length(); i < n; i++) {
char c = str.charAt(i);
//перебор букв
}*/