Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A problem.........

 
Steve Jensen
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic