Eine gute Antwort wäre:

The complete rule is below.

Static View

Here is the complete math-like definition for the Fibonacci series. There are two base cases. This is fine. Recursion breaks problems into smaller pieces. After enough breaking, all that remains are the base cases that can be solved immediately. There can be any number of base cases.

fib( 1 ) = 1       (base case)

fib( 2 ) = 1       (base case)

fib( N ) = fib( N-1 ) + fib( N-2 )

We have a math-like definition. Creating a Java method to implement it should be a nearly mechanical translation from math to Java.

public int fib( int n )
{
  if ( ________ )

    return _______;

  else if  ( ________ )

    return _______;

  else

    return ________ + ________;
}

FRAGE 16:

Sharpen your translation skills by filling those blanks.

Inhaltsverzeichnis