Tuesday, 10 June 2014

Print first 10 numbers from fibonacci series.

class Fibbonaci
{
  public static void main(String [] args)
  {
  int a = 0;
int b = 1, temp;
  System.out.print(a + ", " + b + ", ");
  for(int i = 1; i < 10; i++)
  {
    temp = b;
    b = a + b;
    a = temp;
    System.out.print(b + ", ");
  }
}
}

No comments:

Post a Comment