Problem Statement
You and your friend are waiting in a line. A description of the line is given in the
How far apart are you and your friend in this line?
Definition
- Class:
- FriendFinder
- Method:
- distance
- Parameters:
- String
- Returns:
- int
- Method signature:
- int distance(String line)
- (be sure your method is public)
Constraints
- line will have between 2 and 50 characters, inclusive.
- Each character of line will be '.', 'S', or 'F'.
- 'S' and 'F' will each appear exactly once in line.
Examples
"....SF..."
Returns: 1
You and your friend are adjacent in this line, thus you are one position away from each other.
"S........F"
Returns: 9
You and your friend are at completely opposite ends of this line.
"..F...S.."
Returns: 4
You and your friend may appear in either order.
"S........................................F"
Returns: 41
".................................FS"
Returns: 1
"...S.....F"
Returns: 6
"F..S................."
Returns: 3
"..S.....F..."
Returns: 6
"SF"
Returns: 1
".S........F"
Returns: 9
"SF....."
Returns: 1