Suppose you have one cent ($0.01) in a piggy bank. Each day you double the amoun
ID: 3600682 • Letter: S
Question
Suppose you have one cent ($0.01) in a piggy bank. Each day you double the amount of money you have in the bank. Thus at the beginning - day zero - you have one cent, on day one you have two cents (0.02), on day three you have four cents (0.04) and so forth. The doubleEachDay method takes a double value, jackpot, as its input argument, and calculates the number of days needed to reach or exceed the jackpot amount, starting at 0.01 and doubling each day. The method returns the number of days, numDays, required for doubling. Notice that we have already provided the method's return statement. Finish the doubleEachDay method below. public int doubleEachDay(double jackpot) { double amount = 0.01; int numDays 0; return numDays; //end method CHECK ANSWERExplanation / Answer
Question 1
Answer:
public int doubleEachDay(double jackpot) {
double amount = 0.01;
int numDays = 0;
while(amount <= jackpot) {
amount = amount * 2;
numDays++;
}
return numDays;
}
Question 2
Answer:
int n=5;
while(n < 10000) {
System.out.println(n);
n = n * 5;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.