I'm trying to solve this problem but in stuck in converting my while loop into recursion
Ive managed to implement the printMany function as follows
public static void printMany(int count, String s){
if(count >= 1) {
System.out.print(s);
printMany(count-1, s);
}
}
But the current implementation of the hourglass method still uses loops though it displays the correct output.
public static void hourglass(int numberOfStars, int numberOfSpaces){
while(numberOfStars>0){
printMany(numberOfSpaces++, " ");
printMany(numberOfStars--, "X ");
System.out.println();
}
numberOfSpaces -=2;;
numberOfStars += 2;
while(numberOfSpaces>=0){
printMany(numberOfSpaces--, " ");
printMany(numberOfStars++, "X ");
System.out.println();
}
}
I want to ask, how can I convert this while loop into a recursive call?