Answer:
import java.util.Scanner;
public class demo {
public static String makeStarBucks(int x){
if(x == 1)
return "*$";
else
return "*" + makeStarBucks(x - 1) + "$";
}
public static void main( String args[] ) {
System.out.println(makeStarBucks(6));
System.out.println(makeStarBucks(4));
}
}
Explanation:
Stop the recursion when x reaches 1 which acts as a stopping criteria otherwise keep on doing recursive call by decrementing x by 1 each time.