1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
zhuklara [117]
3 years ago
5

Write code to complete doublePennies()'s base case. Sample output for below program with inputs 1 and 10: Number of pennies afte

r 10 days: 1024 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.
Computers and Technology
1 answer:
UkoKoshka [18]3 years ago
8 0

Answer:

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 */

     if(numDays == 0){

         totalPennies = numPennies;

     }

     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;

  }

}

Explanation:

You might be interested in
A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
Elena L [17]

Answer:

// here is code in java.

import java.util.*;

class Solution

{

// main method of class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // declare variable

         double caffeine;

    // scanner object to read input from user

       Scanner scr=new Scanner(System.in);

       System.out.print("Enter the initial amount of caffeine:");

        // read the initial amount of caffeine

           caffeine=scr.nextDouble();

          // calculate amount of caffeine after 6,12,18 hours

          for(int i=1;i<=3;i++)

          {

               System.out.println("After "+ i*6+" hours:"+(caffeine/2)+" mg");

               // update the caffeine after every 6 hours

               caffeine=caffeine/2;

          }

                 

   }catch(Exception ex){

       return;}

}

}

Explanation:

Create a variable "caffeine" to store the initial amount of caffeine given by user. Run a loop for three time, it will calculate the amount of caffeine left after every 6 hours.First it will give the amount of caffeine left after 6 hours, then caffeine left after 12 hours and in last caffeine after 18 hours.

Output:

Enter the initial amount of caffeine:100

After6 hours:50.0 mg

After12 hours:25.0 mg

After18 hours:12.5 mg

8 0
3 years ago
Robert needs to apply formatting from one set of text to multiple other sets of text throughout the document. Which option shoul
stiks02 [169]

Answer:

I think the answer is option D (double-click Format Painter)

Explanation:

7 0
2 years ago
What function does the ALU perform?
mixas84 [53]
The correct answer is B
6 0
3 years ago
Net Worth is equal to assets minus liabilities. Which event will have the greatest impact (positive or negative) on one's net wo
kolezko [41]
The answer would be: Go on a vacation that costs $3,500 

Paying off money for buying a car will not decrease your net worth as you get the car as assets for the money you use. But the depreciates 20% will cause you to lose $3,000 assets. Assuming you are not buying assets at all, go on a vacation that costs $3,500 will increase liability without any effect on assets. Paying up bills will decrease your asset but it also decreases your liability so the net worth wouldn't change. 
7 0
3 years ago
Which action should you take when sending a large attachment?
zlopas [31]
Cancel out other tasks, let the internet focus upon the one attachment.
7 0
3 years ago
Other questions:
  • Why is driving a privilege?
    15·2 answers
  • in what way do rules and laws created to address public problems affect individuals groups and business
    13·1 answer
  • Which key is used in word processors to create indentations?
    13·2 answers
  • Instructions Write a program that asks the user for a number. If the number is between 1 and 255, the program outputs the corres
    15·1 answer
  • In this context, the word “session” refers to _____.
    5·2 answers
  • Code written by computer programmers is translated to binary code, so computers can understand the instructions. True or False
    7·1 answer
  • Fiber optic cables transfer data at the speed of light, so they have the __________ latency. This results in the ________ connec
    13·1 answer
  • While using a web-based order form, an attacker enters an unusually large value in the Quantity field. The value he or she enter
    15·1 answer
  • ¿Cuáles aspectos serían los que más incidirían para que no se pudiera cumplir con el principio de imparcialidad en una auditoría
    11·1 answer
  • You have been elected to assist the school's yearbook committee and newspaper club in purchasing new computers. The current comp
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!