Answered step by step
Verified Expert Solution
Question
1 Approved Answer
please answer all questions 7. (10 p.) Write recursive mathematical definition for computina the following sequences ja Sumorsquares(n) = 12 + 2 + ... +
please answer all questions
7. (10 p.) Write recursive mathematical definition for computina the following sequences ja Sumorsquares(n) = 12 + 2 + ... + n2 for all nonnegative integers n Sum of square ifn=0 Sum of squares Cortt (b) Factorial(n) = n! for all nonnegative integers n Factorial (nd= I (Factorial (n-1)*n if n=0 if nso 8. (10 p.) Consider the following recursive method: public static int example (int number) { if (number == 0) return 0; return number + example (number - 2): (a) What (if any) is the constraint on the value that can be passed as an argument for this method? number 20 am (6) is example (2) a valid call? If so what is the returned value? Y eve (c) Is example (-8) a valid call? If so what is the returned value? NO (d) Is example (1) a valid call? If so what is the returned value? TPS VO (e) is example (8) a valid call? If so what is the returned value? Yos 9. (10 p.) What is the output of the following Java program? public class Hanoi { public static void main (String[] args) { towersOfHanoi (3, 'A', 'B', 'C'); public static void towersOfHanoi (int n, char first char middle, char last) { if (n > 0) { towersOfHanoi (n - 1, first, last, middle); System.out.println("Move a ring from " + first + " to " + last): towersOfHanoi (n - 1. middle, first, last): Output: "Move a ring from 3 +A+B+L"). Bonus. (8p) A 40 pound stone had been used to weigh 40 pounds of grain with a balanced scale, by putting the stone on one side and the grain on the other side. One day the stone broke into four pieces. Now, using these four pieces any amount of grain can be weighed in 1 pound increments fromStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started