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]
2 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]2 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
Most search engines provide specific pages on which you can search for____ and
vazorg [7]

Answer: c

Explanation: a

7 0
2 years ago
Read 2 more answers
What are the benefits of writing functions that use parameters and return List 2 please and explain what is return
Ratling [72]

<u>Answer and explanation:</u>

There are many benefits of writing functions that use parameters and return. Some of them are:

1. Flexibility: With functions having parameters, several values of the parameters can be used at invocation time thereby making the application flexible. For example, given the following function in Java.

<em>public void showName(String name){</em>

<em>    System.out.println("Your name is " + name);</em>

<em>}</em>

To call this method (function), the programmer could use various values for the name parameter used in the function like so:

showName("John");

showName("Doe");

If the function didn't have a parameter, it is possible it will only print a hardcoded name every time the function is called.

2. Scope Control: When a function is allowed to return a value, it helps to work around scope issues since variables declared within a function are limited to that function and do not exist outside the function. This means that the values of these variables cannot be used anywhere else outside the function in which they are being declared. However, if the function returns a value, the value can be used anywhere else in the program.

For example:

<em>public String getDouble(int x){</em>

<em>    int y = x * 2</em>

<em>    return y;</em>

<em>}</em>

The function above returns twice the value of the argument supplied to it. Since the integer variable y is declared within the function, it's value cannot be used outside the function. However, since the value is being returned by the function, it could be used anywhere the function is being called. Thanks to the return keyword.

3 0
3 years ago
Suppose you have a 16-bit machine with a page size of 16B. Assume that any unsigned 16-bit integer can be a memory address. Also
irinina [24]

Answer:

2^11

Explanation:

Physical Memory Size = 32 KB = 32 x 2^10 B

Virtual Address space = 216 B

Page size is always equal to frame size.

Page size = 16 B. Therefore, Frame size = 16 B

If there is a restriction, the number of bits is calculated like this:  

number of page entries = 2^[log2(physical memory size) - log2(n bit machine)]

where

physical memory size = 32KB  which is the restriction

n bit machine = frame size = 16

Hence, we have page entries = 2^[log2(32*2^10) - log2(16)] = 2ˆ[15 - 4 ] = 2ˆ11

7 0
3 years ago
WILL GIVE BRAINLIEST!!!!!!!!!
sukhopar [10]

Answer:

True

Explanation:

7 0
2 years ago
A merge is _____.
Aliun [14]
The process of combining information from a variety of sources
7 0
3 years ago
Read 2 more answers
Other questions:
  • April 107 90 29 31 66 0.344
    8·1 answer
  • I'm curious why I would need to know this on a school learning site.
    12·1 answer
  • Hard drives are usually self-contained, sealed devices. Why must the case for the hard drive remain sealed closed?
    8·1 answer
  • Fill in the blank. Do not abbreviate.
    6·1 answer
  • Which asynchronous electronic community is also known as a forum?
    9·2 answers
  • Bill Schultz works at a high power investment firm in Los Angeles. Bill is responsible for promoting the firm's vision and creat
    15·1 answer
  • When giving a presentation it is better to ___________
    5·1 answer
  • Universal Containers has two customer service contact centres and each focuses on a specific product line. Each contact centre h
    7·1 answer
  • What version of java do i have installed.
    6·1 answer
  • Which tools can help you gather information about the processes running on a windows operating system?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!