Home Segments Top Top Previous Next

467: Mainline

The following switch statement does the work with no duplication of the return statement:

public class Demonstrate {
 public static int rabbits (int n) {
  switch (n) {
   case 0: case 1: return 1;                            
   default: return rabbits(n - 1) + rabbits(n - 2); 
  } 
 } 
}