Respuesta :
Answer:
public class CalculatePennies {
// Returns number of pennies if pennies are doubled numDays times
public static long doublePennies(long numPennies, int numDays) {
long totalPennies = 0;
/* Your solution goes here */
if(numDays == 0){
totalPennies = numPennies;
}
else {
totalPennies = doublePennies((numPennies * 2), numDays - 1);
}
return totalPennies;
}
// Program computes pennies if you have 1 penny today,
// 2 pennies after one day, 4 after two days, and so on
public static void main (String [] args) {
long startingPennies = 0;
int userDays = 0;
startingPennies = 1;
userDays = 10;
System.out.println("Number of pennies after " + userDays + " days: "
+ doublePennies(startingPennies, userDays));
return;
}
}
Explanation:
The doublePennies() function is an illustration of the recursive function in Java
How to complete the doublePennies() function?
The base case of the doublePennies() function is that:
When the number of days is 0, then the total available pennies is the same as the total number of pennies.
The algorithm of the above highlight is:
if numDays equals 0 then
totalPennies = numPennies
Using the above algorithm, the complete base case is:
if(numDays == 0){
totalPennies = numPennies;
}
Read more about Java programs at:
https://brainly.com/question/26642771