The last three tasks are not passing although I believe my code is correct.
Also, I am getting the error "Bear in mind that strings entered from the keyboard may contain not only letters, but also other symbols." Nowhere in the description does it ask for this? Thanks.
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
// initialize a hashMap with count
HashMap<Character, Integer> countMap = new HashMap<>();
// add letters to HashMap from alphabet
for (int i = 0; i < alphabet.size(); i++)
{
countMap.put(alphabet.get(i), 0);
}
// loop through list and use toCharArray to split strings
for (int i = 0; i < list.size(); i++)
{
char[] charArray = list.get(i).toCharArray();
// next loop through charArray and increment hashMap count
for (int j = 0; j < charArray.length; j++)
{
Integer count = countMap.get(charArray[j]);
countMap.put(charArray[j], ++count);
}
}
// loop through HashMap and print out key and value seperated by space
for (Map.Entry<Character, Integer> pair : countMap.entrySet())
{
System.out.println(pair.getKey() + " " + pair.getValue());
}
}
}
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
// initialize a hashMap with count
HashMap<Character, Integer> countMap = new HashMap<>();
// add letters to HashMap from alphabet
for (int i = 0; i < alphabet.size(); i++)
{
countMap.put(alphabet.get(i), 0);
}
// loop through list and use toCharArray to split strings
for (int i = 0; i < list.size(); i++)
{
char[] charArray = list.get(i).toCharArray();
// next loop through charArray and increment hashMap count
for (int j = 0; j < charArray.length; j++)
{
Integer count = countMap.get(charArray[j]);
countMap.put(charArray[j], ++count);
}
}
// loop through HashMap and print out key and value seperated by space
for (Map.Entry<Character, Integer> pair : countMap.entrySet())
{
System.out.println(pair.getKey() + " " + pair.getValue());
}
}
}