java - Fibonacci calculation -


this program supposed fibonacci number user , program calculate while making sure user entered positive number , number no less fibonacci number 70. so, if user entered 7, should print 13. method fibcalc() supposed calculations. when try , compile program, errors "method fibcalc in class fibonacci cannot applied given types: system.out.printf("fibonacci #%d %f", num, fibcalc(num, x3)); , "cannot find symbol" return x3;here's code:

import java.util.scanner;  public class fibonacci {     public static void main ( string args[] )      {     scanner input = new scanner ( system.in );          int num;          double x3 = 0;              system.out.print("which fibonacci number like? ");        num = input.nextint();                    {         system.out.print("which fibonacci number like? ");         num = input.nextint();      }while(num >= 0 && num <= 70);      system.out.printf("fibonacci #%d %f", num, fibcalc(num, x3));  }   public static double fibcalc(int num)  {     int x1 = 0;     int x2 = 1;          if (num == 0)              return 0;          else if (num == 1)              return 1;          else              (int x3 = 0; x3 < num; x3++)                 {                     x3 = x1 + x2;                     x1 = x2;                     x2 = x3;                 }                 return x3;  }   } 

there other problems i've missed. i'm pretty new java. in advance.

the fibcalc() method has single int parameter, calling two parameters.

change call from

fibcalc(num, x3) 

to

fibcalc(num) 

ie change line to:

system.out.printf("fibonacci #%d %f", num, fibcalc(num)); 

also, if want accurate numbers results, change using double using biginteger, can handle arbitrarily large numbers accurately.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -