• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

counting the alpabits

 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the following program to count the all the alphabits in a string but it doesn't work i don't know why

 
Paweł Baczyński
Bartender
Posts: 1796
33
Firefox Browser IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does it mean "doesn't work"? Does it compile? Does it run? If it does run what are your results and what did you expect?
ItDoesntWorkIsUseless <- click this and read
What are 'alphabits '?
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i mean by it doesn't work that it compiles and run but not giving me the needed results. sorry for confusion.
what i want is to count all the letters of the alphabits in any input string. such as A is 5 times, B is 7 times etc....
 
Paweł Baczyński
Bartender
Posts: 1796
33
Firefox Browser IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean 'alphabet' ?
What result did you expect and what result did you get?

I see you are overcomplicating this. Why do you split the string?
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i split the string because i want to enter a complete sentense not even one full word.
 
Paweł Baczyński
Bartender
Posts: 1796
33
Firefox Browser IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok but why can't you just search the characters in a whole sentence? Why do you need to search in every word separately?
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean to conver the sentense to char array to search within
 
Paweł Baczyński
Bartender
Posts: 1796
33
Firefox Browser IntelliJ IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you need to convert anything? You can iterate over String (from 0 fo str.length()-1) and count every individual character if it is a letter.
No need to split or convert anything.
 
Mohamad Samy
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, i will try to solve it your way. thanks
 
Henry Wong
author
Marshal
Pie
Posts: 21184
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

A couple of points...

1. You only look for upper case letters. Lower case letters don't count.

2. You only count each letter once per word. For example, the word "ZOO" will get you one "O" and one "Z".

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic