next up previous
Next: Send in the second Up: Part One Previous: Mess around with Strings

Loopage!


\begin{figure}
\centerline{
\psfig {figure=fig_ass6.eps,width=3.0in}
}\end{figure}

Yet another method you can invoke on Strings is charAt. Unlike the other methods we have used, charAt takes an argument, an integer indicating which character you want. Something that indicates is called an index. In Java, as in many other languages, indices start are zero instead of one. See the figure for details.

WARNING: There is no character with index equal to the length of the String. The indices run from 0 to name.length()-1.

1.
Write a for loop that goes through each letter of the String, selects each letter using charAt and prints each letter on a separate line.
2.
Write a loop that prints the characters in the String backwards, all on the same line. Don't forget that you have to have a println somewhere after all the prints, or nothing will appear on the screen.



Allen B. Downey
3/11/1998