Problem Simple1
Problem Statement
The square length of a string is the square
of the number of characters in the string. The square length
of "hello" is 25, the square length of "a"
is 1, and the square length of "apple sauce" is 121.
Given a string, write a function that returns the string's
square length.
Definition
- Class: SquareLength
- Method: length
- Parameters: String
- Returns: int
- Method signature (see below)
Prototype
public class SquareLength
{
public int length(String str)
{
// fill in code here
}
}
Constraints
- The square length of the parameter s will be
less than
INT_MAX, you do not need to
worry about integer overflow.
Examples
(quote for clarity, they're not part of the string)
-
"hello"
Returns: 25
From above
-
"apple sauce"
Returns: 121
-
""
Returns:0
The empty string has zero length.
-
"dorothy the dinosaur"
Returns: 400
Owen L. Astrachan
Last modified: Wed Jul 23 11:10:49 EDT 2003