开发者

How to count occurances of a character in file?

开发者 https://www.devze.com 2023-01-15 03:23 出处:网络
I want to print no. of a, b, c,etc... Special characte开发者_如何学JAVArs, vowels, consonants in file using Java. how to do that?

I want to print no. of a, b, c,etc... Special characte开发者_如何学JAVArs, vowels, consonants in file using Java. how to do that?


  1. create map <char, int>
  2. read file char by char.
  3. if char in map -> map.put(map.get(char)+1) else map.put(char, 1)


  1. Open the file
  2. Go through the file character by character.
  3. If the current char matches the char you want,increment the counter by one
  4. Detect end of file (EOF) and print the counter value.

Read File Handling , InputStream

Give it a try and if you are stuck at something specific,come back with the specific question.

0

精彩评论

暂无评论...
验证码 换一张
取 消