So I understand the task in the following way:
-example: check if the word contains the letter "a", if yes increment the respective counter. So if every word (total of 10 inputs) has the letter 'a' in it then the output for the first line should be: a 10 .
And my code does that, but the 3rd condition is not validated.
Thanks in advance!
package com.codegym.task.task10.task1012;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
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());
}
int[] counters = new int[26];
for (int i = 0; i < counters.length ; i++) {
for (int j = 0; j < 10 ; j++) {
if(list.get(j).indexOf(alphabet.get(i)) != -1){
counters[i]++;
}
}
}
for (int i = 0; i < counters.length ; i++) {
System.out.println(alphabet.get(i)+ " " + counters[i]);
}
// write your code here
}
}