Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi I really neeeeeed heeeelp for to understand this program project for recursio

ID: 3681383 • Letter: H

Question

hi I really neeeeeed heeeelp for to understand this program project for recursion i dont know how to start on it can someone explain more to what i need to do and help me to get started i really appreciate it it is due very soon I need it right away thank you
Recall that the Fibonacci Sequence (0, 1, 1, 2, 3, 5, 8, 13, . . . ) is the sequence having 0
and 1 as its first two elements and in which each subsequent element in the sequence is
the sum of the two preceding elements.
= 1 + 2, = 2,3,... fn fn fn n
According to a theorem, any positive integer can be expressed as the sum of one or more
Fibonacci numbers such that no number occurs more than once in the sum, and no two
consecutive Fibonacci numbers occur in the sum (i.e., fi and fi+1) in the sequence.
For example, the (only) Fibonacci sum of 14 is 13 + 1. Although 5+3+2+2+2 = 14, it is
not a Fibonacci sum, on at least two separate grounds. First, 2 is used three times, while
the theorem prohibits even two occurrences of the same number. Second, 3 and 5 are
consecutive Fibonacci numbers, while the theorem prohibits the use of two such
numbers.
Develop a program that accepts as input a nonnegative integer and produces as output a
Fibonacci sum of that integer. The values in the sum should be written in decreasing
order, with plus signs ("+") between them (as illustrated below). Your program should
repeat until a zero or negative number is entered.
Sample input
30
515
14
Sample output
30= 21 + 8 + 1
515 = 377 + 89 + 34 + 13 + 2
14 = 13 + 1
Hints:
• Re-cast the theorem as
n = fj + (n - fj )
• This suggests a recursive solution.

Explanation / Answer

package assignment;

import java.util.ArrayList;

public class FibnocciSumInt {
   public static void main(String args[]) {
       String sum = numAsFibnocci(30);
       System.out.println(sum);

       sum = numAsFibnocci(515);
       System.out.println(sum);
      
       sum = numAsFibnocci(14);
       System.out.println(sum);
   }
  
  
   //Re-cast the theorem as
   //n = fj + (n - fj )
   public static String numAsFibnocci(int n) {
       String str = "";
       if(n <= 2) {
           if(n > 0)
               str += n;
           return str;
       }
       else {
           int maxfib = fibnocci(n);
           str += maxfib;
           return str+(!"".equals(str) ? "+" : "")+numAsFibnocci(n-maxfib);
       }
   }
  
  
   public static int fibnocci(int maxnum) {
       int n1 = 0, n2 =1, n3 = 0;
       int i = 0;
       while(n3 <= maxnum) {
           n3 = n2+n1;
           n1 = n2;
           n2 = n3;
           if(n1+n2 > maxnum)
               break;
       }
       return n3;
}

--output-------------

21+8+1
377+89+34+13+2
13+1