go to previous page   go to home page   go to next page

Answer:

A string that contains no characters has length 0.


Length of a String

Let us write a method that computes the length of a string. The Java class String includes a method length() so it seems odd to write such a method. But string length is a really good example of recursion. Pretend that the people who wrote String forgot to include a length() method, so now you are stuck with the job.

What is the length of each of the strings in the table?

StringLength
"DOG"
"A"
""   (the empty string)
" "   (the space character)
"Dogs and Cats"

QUESTION 2:

Say that you know that the length of

uperfragilisticexpialadocious

is 29. What is the length of

Superfragilisticexpialadocious

go to previous page   go to home page   go to next page