public static void main(String args [])
{
Scanner in = new Scanner(System.in);
int number = 0;
do{
System.out.print("Which Fibonacci Number would you like? ");
number = in.nextInt();
}while(number < 0 || number > 71);
System.out.printf("Fibonacci #%d is %d\n",number, fibcalc(fib));
}
public static double fibcalc(int number)
{
double prevNumber1 = 0;
double prevNumber2 = 1;
double fib = 0;
for(int i =0; i < number; i++){
fib = prevNumber1;
prevNumber1 = prevNumber2;
prevNumber2 = fib + prevNumber2;
}
return fib;
}
The code above is what I have.
Following is the error I keep on getting:
error: cannot find symbol
System.out.printf("Fibonacci #%d is %d\n",number, fibcalc(fib));
^
symbol: variable fib
location: class dlin_Fibonacci
It is saying that it cannot find
fibcalc(fib)
I want to return the value of fib from my fibcalc method, so I can print it in my main method.
Does anyone know why it is not letting me?
I attempted in using just the variable fib, but the result is the same error message.
Does this have to do with the fact that variable fib is a local variable and not a class variable? If it is, then how do make it a class variable?
I tried moving the variable fib and number above my main method. Something like…
private static int number = 0;
private static double fib = 0;
public static void main(String arg[])
However, this gave me error: illegal start of an expression for the variables.
Also, can someone tell me if I am doing the return statement right?
I did some research into that going to varies sites watching videos. It seem like I followed every step. However I still don’t under what it mean by “passing the parameter”
which is the variable inside of the () within a method. does that variable comes from other method or is it just created within the method that is written? like my example above, will the variableint number be passed from my main method to my fibcalc method simply by stating it in within the ()?
fibis not in scope since it’s local tofibcalc. Change the line like this: