subject
Computers and Technology, 18.02.2020 17:23 des9263

Write code to complete doublePennies()'s base case. Sample output for below program:

Number of pennies after 10 days: 1024
Note: These activities may test code with different test values. This activity will perform three tests, with startingPennies = 1 and userDays = 10, then with startingPennies = 1 and userDays = 40, then with startingPennies = 1 and userDays = 1. See How to Use zyBooks.
Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds, and report "Program end never reached." The system doesn't print the test case that caused the reported message.
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 */

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;
}
}

QUESTION 2

Write code to complete printFactorial()'s recursive case. Sample output if userVal is 5:

5! = 5 * 4 * 3 * 2 * 1 = 120
public class {
public static void printFactorial(int factCounter, int factValue) {
int nextCounter = 0;
int nextValue = 0;

if (factCounter == 0) { // Base case: 0! = 1
System. out. println("1");
}
else if (factCounter == 1) { // Base case: Print 1 and result
System. out. println(factCounter + " = " + factValue);
}
else { // Recursive case
System. out. print(factCounter + " * ");
nextCounter = factCounter - 1;
nextValue = nextCounter * factValue;

/* Your solution goes here */

}
}

public static void main (String [] args) {
int userVal = 0;

userVal = 5;
System. out. print(userVal + "! = ");
printFactorial(userVal, userVal);

return;
}
}

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:00, kebo63
Page orientation can be either landscape or
Answers: 1
image
Computers and Technology, 23.06.2019 10:00, uwunuzzles
How do i delete my account on this because i didn't read this agreements and also i put age at xd
Answers: 1
image
Computers and Technology, 23.06.2019 20:40, bobby3350
On nba 2k 19, every time i try to join a my park game, it leads ro a website telling my dad that he needs ps plus. i already have ps plus though. how do i fix this?
Answers: 2
image
Computers and Technology, 23.06.2019 22:50, christingle2004
What is an rss reader used for? for creating a user account on a social new site
Answers: 2
You know the right answer?
Write code to complete doublePennies()'s base case. Sample output for below program:

Num...

Questions in other subjects:

Konu
Mathematics, 03.12.2020 01:00
Konu
Mathematics, 03.12.2020 01:00
Konu
Mathematics, 03.12.2020 01:00
Konu
Biology, 03.12.2020 01:00
Konu
Mathematics, 03.12.2020 01:00