This has been giving me a headache all day and I cannot figure it out. The goal is to have the string repeat itself using the times param as the number of times the string is able to repeat its self. for example:
stringTimes("Hello", 3); //should return HelloHelloHello,
stringTimes("cat", 2); //should return catcat,
stringTimes("monkey", 0); //should return _____,
below is the code I've been using and I'm getting nothing. HELP!!!
public static String stringTimes(String theString, int times)
{
String adder = "";
if (times >= 1) {
adder += theString;
return stringTimes(theString, times - 1);
}
return adder;
}
public static void main(String[] args) {
System.out.println(stringTimes("hello ", 8 ));
}