I am writing a program that calculates Fibonacci numbers... But I keep getting an error on my code when I try to compile it...:
Fibonacci.java:18: illegal start of expression
public int calcFib (int n) {
^
1 error
I don't know what I am doing wrong? Someone help? Here's my code:
import java.util.Scanner;
public class Fibonacci {
public static void main(String[] args) {
int fib;
int n;
Scanner scan = new Scanner(System.in);
System.out.println("input a number");
n = scan.nextInt();
public int calcFib (int n) {
int ans;
if (n<2) {
ans = n;
return ans;
}
else {
ans = (n-1) + (n-2);
return ans;
}
}
System.out.println(calcFib(n));
}
}