Need help with this java code on implementing Fibonacci sequ
Need help with this java code on implementing Fibonacci sequence and Factorial. Please fill in the parts indicated \"//Fill-in and Fix\". Please do not alter any of the other code already implemented on there. Sample outputs are given below. Thank you!
public static long fib (int max) long fibNum 30; //Fill-in, Fix for (int i 2; i maxi it fibNum i; return fibNum; public static long fib (long arr, int max) long fibNum 0; Fill-in, Fix for (int i 2; iSolution
public class FactFib {
public static long fib(int max){
long n0=0;
if(max==0)return n0;
long n1=1;
if(max==1)return n1;
int count = 2;
long next_n = n0+n1;
while(count<max+1){
next_n = n0+n1;
n0=n1;
n1=next_n;
count++;
}
return next_n;
}
public static long fib(long[] arr , int max){
arr = new long[max];
long n0=0;
if(max==0)return n0;
long n1=1;
if(max==1)return n1;
arr[0]=n0;
arr[1]=n1;
int count = 2;
long next_n = n0+n1;
while(count<max+1){
next_n = n0+n1;
arr[count] = next_n;
n0=n1;
n1=next_n;
count++;
}
return next_n;
}
public static long factorial(int max){
long facNum = 0;
facNum=1;
for(int i=2;i<=max;i++){
facNum = facNum*i;
}
return facNum;
}
public static long factorial(long[] arr,int max){
long facNum = 0;
facNum=1;
arr[1]=facNum;
for(int i=2;i<=max;i++){
facNum = facNum*i;
arr[i] = facNum;
}
return facNum;
}
public static void main(String[] args) {
System.out.println(fib(5));
System.out.println(factorial(5));
}
}

