Problem Statement
The definition of how to multiply a string by an integer follows:
- The empty string ("") multiplied by any integer is the empty string ("").
For example: "" * 9 = "" - Any string multiplied by 0 is the empty string ("").
For example: "Terrific" * 0 = "" - A non-empty string S multiplied by a positive integer k is the concatenation
of k occurrences of S.
For example: "Great" * 4 = "GreatGreatGreatGreat" - A non-empty string S multiplied by a negative integer k is the concatenation
of k occurrences of the reverse of S.
For example: "Great" * -4 = "taerGtaerGtaerGtaerG"
Definition
- Class:
- StringMult
- Method:
- times
- Parameters:
- String, int
- Returns:
- String
- Method signature:
- String times(String sFactor, int iFactor)
- (be sure your method is public)
Constraints
- sFactor will have length between 0 and 50 inclusive.
- iFactor will be between -50 and 50 inclusive.
- sFactor will contain only letters ('A'-'Z' and 'a'-'z').
- The length of the returned String (sFactor*iFactor) will be between 0 and 50, inclusive.
Examples
"wOw"
0
Returns: ""
"AbC"
-3
Returns: "CbACbACbA"
"Boo"
4
Returns: "BooBooBooBoo"
""
50
Returns: ""
"Racecar"
-5
Returns: "racecaRracecaRracecaRracecaRracecaR"