Problem Statement
- 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"
"a"
50
Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"a"
-50
Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"
1
Returns: "abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"
"abcdefgHIJKLMNOPqrstuvWXYZcdefgHIJKLMNOPqrstuvWXYZ"
-1
Returns: "ZYXWvutsrqPONMLKJIHgfedcZYXWvutsrqPONMLKJIHgfedcba"
"AbCdEfG"
7
Returns: "AbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfGAbCdEfG"
"AbCdEfG"
-7
Returns: "GfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbAGfEdCbA"
"uapoifusdapofuaspodu"
0
Returns: ""
"oaiufpoiasudfpoiuasioasdu"
2
Returns: "oaiufpoiasudfpoiuasioasduoaiufpoiasudfpoiuasioasdu"
"AAA"
16
Returns: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"AAA"
-16
Returns: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"GreatProblem"
4
Returns: "GreatProblemGreatProblemGreatProblemGreatProblem"
"TerrificProblem"
-3
Returns: "melborPcifirreTmelborPcifirreTmelborPcifirreT"
"Fubar"
10
Returns: "FubarFubarFubarFubarFubarFubarFubarFubarFubarFubar"
"BlahBlah"
4
Returns: "BlahBlahBlahBlahBlahBlahBlahBlah"
"test"
5
Returns: "testtesttesttesttest"
"fubar"
-10
Returns: "rabufrabufrabufrabufrabufrabufrabufrabufrabufrabuf"
"test"
-5
Returns: "tsettsettsettsettset"
"Racejoemom"
-5
Returns: "momeojecaRmomeojecaRmomeojecaRmomeojecaRmomeojecaR"
"googleplex"
-5
Returns: "xelpelgoogxelpelgoogxelpelgoogxelpelgoogxelpelgoog"
"wOw"
0
Returns: ""
"Suny"
5
Returns: "SunySunySunySunySuny"
"nwfniwng"
-3
Returns: "gnwinfwngnwinfwngnwinfwn"
"AbCdE"
-9
Returns: "EdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbAEdCbA"
"AbC"
-3
Returns: "CbACbACbA"