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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 08:00
Aplan to budget time for studying and activities is referred to as a study routine. study habits. study skills. a study schedule.
Answers: 1
question
Computers and Technology, 22.06.2019 19:20
Amedian in the road will be marked with a white sign that has a black arrow going to the left of the median. true false
Answers: 1
question
Computers and Technology, 22.06.2019 21:40
Develop a function to create a document in the mongodb database “city” in the collection “inspections.” be sure it can handle error conditions gracefully. a. input -> argument to function will be set of key/value pairs in the data type acceptable to the mongodb driver insert api call b. return -> true if successful insert else false (require a screenshot)
Answers: 2
question
Computers and Technology, 23.06.2019 06:00
Which statistical function in a spreadsheet you to see how far each number varies, on average, from the average value of the list?
Answers: 2
You know the right answer?
Write code to complete doublePennies()'s base case. Sample output for below program:

Num...
Questions
question
Mathematics, 20.05.2020 04:01
question
Mathematics, 20.05.2020 04:01
question
Social Studies, 20.05.2020 04:01
question
History, 20.05.2020 04:01
Questions on the website: 13722367