Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Homework number 4 - fibonacci sussquences.

Name: Anonymous 2010-01-19 4:00

Consider the generalized fibonacci sequences:
4, 1, 5, 6, 11, 17, 28, ...
3, 2, 5, 7, 12, 19, 31, ...
Write a program that takes two numbers as input and prints as many Sussmans as the tenth number in the resulting fibonacci sequence.
USE RECURSION.

Name: Anonymous 2010-01-19 14:29

import java.io.*;
public class PROGHomework
{
   public static void main(String[] args)
   {
      int a = 0;
      int b = 1;
      Sussquences.fiba(a,b,10);
   }

   static class Sussquences
   {
      // Parameter 'c' is the position of the Fibonacci element you want returned
      public static void fiba(int a, int b, int c)
      {
         if(c <= 0) { return; }
         else if(c == 1)
         {
            while(a > 0) { System.out.print("Sussman "); a--; }
         }
         else if(c-2 == 0)
         {
            while(b > 0) { System.out.print("Sussman "); b--; }
         }
         else { fiba(b, a+b, c-1); }
      }
   }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List