I have the following code which provides the correct values for n < 47.
public static int fib(int n) { int nthTerm = 0; if (n == 2) nthTerm =
Use long instead of using int, and remember to cast the value from Math.round() to long as well (by writing (long) Math.round(...) just as you casted to int) .
long
int
Math.round()
(long) Math.round(...)