全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写Section Readings: 2.3

Problem 1. (Sum of Integers) Implement the static methods sumIter() and sumRec() in

SumOfInts that take an integer argument n and return the sum S(n) = 1 + 2 + 3 + · · · + n,

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写computed iteratively (using a loop) and recursively. The recurrence relation for the latter

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写implementation is

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写$ java SumOfInts 100

5050 5050

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写Problem 2. (Exponentiation) Implement the static method power() in Power that takes

two integer arguments a and b and returns the value of a

the recurrence relation

$ java Power 3 5


Problem 3. (Bit Counts) Implement the static methods zeros() and ones() in Bits that

takes a bit string (ie, a string of zeros and ones) s as argument and returns the number

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写of zeros and ones in s, each computed recursively. Hint: First devise an appropriate

recurrence relation for the problem.

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写$ java Bits 1010010010011110001011111

zeros = 11 , ones = 14 , total = 25

Problem 4. (String Reversal) Implement the static method reverse() in Reverse that

全优代写 - 北美Essay代写,Report代写,留学生论文代写作业代写takes a string s as argument

Leave a Reply

Your email address will not be published. Required fields are marked *