public static String repeater(int x, String word) {
if (x > 0) {
System.out.print(word.charAt(0));
}
if (x == 0) {
return "";
} else {
return repeater(number-1, x);
}
This code gives me the output I want which is basically taking the first letter of a String and printing it 'x' number of times:
Example:
when my
String = Hello
and x = 6
HHHHHH
My problem is I want this method to work the same way but without the use of the 'System.out.print()' line. Am I going to have to add a second String? If not, what approach should I take?