Count letters in a string Java

前端 未结 5 1351
一向
一向 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 10:04

    • Create an integer array of length 26.
    • Iterate each character of the string, incrementing the value stored in the array associated with each character.
    • The index in the array for each character is calculated by x - 'a' for lower case characters and x - 'A' for upper case characters, where x is the particular character.

提交回复
热议问题