Forums Register Login

A problem.........

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
That's a very big dog. I think I want to go home now and hug this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1131 times.
Similar Threads
Random Password Generation Tool?
HashMap and Vector
Array without ints
need help
Word count problem.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:24:08.