class Solution {
static long nthFibonacci(long n){
// code here
long[] arr = new long[n+1];
arr[0] = 0;
arr[1] = 1;
long i = 2;
for( i = 2; i<= n; i++){
arr[i] = arr[i-1] + arr[i-2];
}
return arr[n];
}
}
class Solution {
static long nthFibonacci(long n){
// code here
long[] arr = new long[n+1];
arr[0] = 0;
arr[1] = 1;
long i = 2;
for( i = 2; i<= n; i++){
arr[i] = arr[i-1] + arr[i-2];
}
return arr[n];
}
}
ERRORS THAT I M GETTING --> prog.java:26: error: incompatible types: possible lossy conversion from long to int long[] arr = new long[n+1]; ^ prog.java:31: error: incompatible types: possible lossy conversion from long to int arr[i] = arr[i-1] + arr[i-2]; ^ prog.java:31: error: incompatible types: possible lossy conversion from long to int arr[i] = arr[i-1] + arr[i-2];
Hey @ayush_r18,
The RHS of these lines is type int.
You need to type cast it into long.
use it like 0L, 1L
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.