Write My Paper Button

WhatsApp Widget

In java please. SumOfPowerOfTwo The following program can be done in a single class. Write a…

Homework Help Question & Answers

In java please. SumOfPowerOfTwo The following program can be done in a single class. Write a…

In java please.

SumOfPowerOfTwo

The following program can be done in a single class.

Write a program that requests and reads in a integer number between 1 and 40 inclusively. Repeat the loop until a proper number is entered.

Call the method powersOfTwoSum with the number as the actual parameter. Expect a value of type long as a return value.

powersOfTwoSum(int number)

This method must use a recursive technique to return the sum of the powers of two from the number down to zero. For example, if the input is 5 the return value would be:

25 + 24 + 23 + 22 + 21 +1

Two Samples:

Enter an integer between 1 and 20 inclusively: 2

The sum of the powers of two from 0 to 2 is 7

Enter an integer between 1 and 40 inclusively: 40

The sum of the powers of two from 0 to 40 is 2199023255551

0 0
Add a comment
Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?