Write the definition of a method named makeStarBucks that receives a non-negative integer n and returns a String consisting of n asterisks followed by n dollars signs. So, if the method received 5 it would print: *****$$$ and if received 3 it would print ***$$

The methos must not use a loop of any kind (for, while, do-while) to accomplish its job.

Respuesta :

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.