File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes counting the alpabits Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "counting the alpabits" Watch "counting the alpabits" New topic
Author

counting the alpabits

Mohamad Samy
Ranch Hand

Joined: Apr 26, 2013
Posts: 98
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

Joined: Apr 18, 2013
Posts: 1021
    
  16

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 '?


Formely Pawel Pawlowicz
Mohamad Samy
Ranch Hand

Joined: Apr 26, 2013
Posts: 98
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

Joined: Apr 18, 2013
Posts: 1021
    
  16

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

Joined: Apr 26, 2013
Posts: 98
i split the string because i want to enter a complete sentense not even one full word.
Paweł Baczyński
Bartender

Joined: Apr 18, 2013
Posts: 1021
    
  16

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

Joined: Apr 26, 2013
Posts: 98
do you mean to conver the sentense to char array to search within
Paweł Baczyński
Bartender

Joined: Apr 18, 2013
Posts: 1021
    
  16

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

Joined: Apr 26, 2013
Posts: 98
ok, i will try to solve it your way. thanks
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18977
    
  40


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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: counting the alpabits