Question
JAVA Write code to complete doublePennies()'s base case. Sample output for below program: Number of pennies after 10 days: 1024 CODE BELOW public class CalculatePennies
JAVA Write code to complete doublePennies()'s base case. Sample output for below program:
Number of pennies after 10 days: 1024
CODE BELOW
public class CalculatePennies { // Returns number of pennies if pennies are doubled numDays times public static long doublePennies(long numPennies, int numDays) { long totalPennies;
if(numDays == 0){ totalPennies = numPennies; } } return totalPennies; }
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; int userDays;
startingPennies = 1; userDays = 10; System.out.println("Number of pennies after " + userDays + " days: " + doublePennies(startingPennies, userDays)); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started