Count letters in a string Java

前端 未结 5 1350
一向
一向 2020-12-10 09:33

I\'m doing an assignment where I\'ll have to code a program to read in a string from user and print out the letters in the string with number of occurrences. E.g. \"Hell

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 09:58

    You can create an Array which first element will represent 'a', second 'b', etc. If you need distinction between lower and upper cases than you can add it at the end. This array will have all values equals 0 at the beginning. Then you iterate through your sentence and you increment required values on the array. At the end you print all values that are > 0. Simple?

    Let me know if you need more help

提交回复
热议问题