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.

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.

LANGUAGE: JAVA

CHALLENGE:

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 method must not use a loop of any kind (for, while, do-while) to accomplish its job.

SOLUTION:

public static String makeStarBucks(int n){
    if(n == 0)
    {
        return "";
    }
    else
    {
        return "*" + makeStarBucks(n - 1) + "$";
    }
} 

Add comment