Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago