Number of letters

  • 12
  • Locked
Have you ever thought that there are too many letters in the alphabet? Computers are able to get by quite well with two, but we have 26. This is an inadmissible excess! Still, we do have to accept reality and complete relevant tasks. Here's one: Enter 10 strings from the keyboard and count the number of different letters in them.
You can't complete this task, because you're not signed in.
Comments (24)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
schipplock Backend Developer at n/a
10 August 2021, 06:20
I had the feeling that something is missing in the description. Also there is "Example output" but no "Example input" which would help a lot.
Justin Smith
Level 38 , Greenfield, USA, United States
25 July 2021, 01:04
I think some of the code that comes with this is really unnecessary and makes it harder than it needs to be. You can just iterate through the abc string using charAt. You don't need the array or ArrayList that it converts the string into. I thought maybe it would fail validation for not using those, but I completely ignored them and my solution passed.
Level 18
21 July 2021, 12:44
I used a hash map to solve this, the keys being the letters in the alphabet and the value the count.
Level 11 , Banja Luka, Bosnia and Herzegovina
29 March 2021, 11:44
I've solved it on my own and then looked upon the suggested solution. Too much complications, nested loops/ifs.. What I did: - converted provided list to a string (to get an uninterrupted 'stream' of characters without empty spaces between them), - converted that string back to ArrayList, - used for loop to iterate over this ArrayList and counted interated characters with Collections.frequency (I suppose I could iterate over String as well without ArrayList). Done. Hard task made easy.
Level 14 , United Kingdom
7 April 2021, 04:04
I do like your approach and I've just solved the task using quite similar one: -read the strings into one StringBuilder -converted StringBuilder into char array -converted char array into my input ArrayList -iterated over provided alphabet ArrayList with Collections.frequency on my input ArrayList
Level 15 , United Kingdom
9 October 2020, 19:19
I was so proud of myself when I finished this without any help or googling, until I updated the IntelliJ Codegym plugin and saw the new "Get correct solution" feature. The suggested solution was so much simpler. I used HashMap and 2 nested loops as opposed to a simple array and 1 nested loop.
Level 41
18 November 2020, 12:43
Yes, that's exactly how I did it and felt!! hahaha! But man, the solution is so sleek and sexy, wow...
Level 18 , Sofia, Bulgaria
20 January 2021, 09:44
Same here...I have used: - one string builder; - one lambda expression; - one counter; - nested for loops ( one for the alphabet and one for the char array ); ...and I have downloaded codegym's solution to see such a simple solution... Love you, CodeGym! What I have done: using lambda expression I have appended each string from the list in a StringBuilder. Next, I have made a new char Array, made of the StringBuilder -> toString -> toCharArray. One counter to count the occurrences in the char Array. Two nested for loops to loop for each letter in the alphabet, check and count in the char Array -> print it, set the counter to 0 and keep going till I reach 'z' ...
Jurij Thmsn
Level 29 , Flensburg, Germany
5 February 2021, 15:06
Me too - I wrote a long spaghetti code with 5 additional for-loops and additional ArrayLists. It took me 20 minutes and it worked on the first try. i was proud of myself until I saw the "right solution" :D this is so much more intelligent O_O
Level 23 , Columbia, United States
30 July 2020, 03:57
2 hours later and some help, got it. You really gotta know the syntax well. I had to learn more about for each loops for this one. I went through the entered String ONE AT A TIME (using a for each loop). Only way I was able to solve it.
Artur Verdyan
Level 24 , Hoboken, United States
2 May 2020, 22:39
I do not know why but I always spend a lot of time just in understanding what the task is asking. I used some websites where you can practice you skills by solving tasks and never had such problem before.Everything were clear... Maybe I'm silly...
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
19 March 2020, 00:03
This was not easy. I see plenty skipped it Two dicta: --if it were easy, anybody could do it --I came here for the practice/ I did it
Level 41
18 November 2020, 12:44
Exactly, some students don't bother trying and trying, they are looking for the quick result... and that's a shame.. it took me about 2 hours and 1 page of a big notebook but when I finished it, it was very satisfying! Plus, I got the chance to deepen my knowledge by revisiting lessons and trying to find out new things.
Kent Hervey Software Engineer/Consult at Zeal IT ConsultantsExpert
18 March 2020, 22:20
Is the example output which shows 9 z and 0 e supposed to work with the below input given/ Because it certainly has no z characters and certainly has more than one e Car Break Racer Phone Game Prophet Apple Tea Tree Car
RKVengatesh Enterprise Java Developer at Fragma Data Systems
15 October 2019, 14:51
what's wrong in 3rd and 4th condition ?
Level 41
16 October 2019, 05:55
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at