aspose file tools*
The moose likes Beginning Java and the fly likes A problem......... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A problem........." Watch "A problem........." New topic
Author

A problem.........

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Folks, i've typed in another program from Ivor Horton's most excellent "Beginning Java 2", and have a query regarding it.
The program is about counting the number of whitespaces, vowels, and consonants in a string variable.
OK, no problem there.
The code is listed below.


I sort of understand the code, apart form the line:-
char ch = Character.toLowerCase(text.charAt(i));

What's going on here?
So we've defined a variable ch, of type ch. But then what? I can't figure out what we're doing with it.
Any help would be greatly appreciated.
Cheers


John Bonham was stronger, but Keith Moon was faster.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Hi Steve,
It takes the i-th character of text, and converts it to lowercase. The text.charAt(i) is the i-th character of the String text.
toLowerCase() is a static method of the Character wrapper class.
He changes the character ch to lowercase so that 'A' and 'a' can be compared in one single expression: ch == 'a' rather than with ( ch == 'a' ) || ( ch == 'A' )
[ February 01, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: A problem.........