Given the following function in pseudocode with n as an inpu
Given the following function (in pseudo-code), with n as an input parameter and n is a positive
number:
int function f(n)
{
if n <= 3 then return 0
else {
sum=f(n-3)+f(n- 2)+f(n-1)
for i=1 to n do
{
for j=1 to n do
{
sum=sum+i*j
}
return sum
}
}
write a Java program that computes f(1), f(2), f(3), f(4), f(5), and f(6).
Solution
import java.util.*;
import java.lang.*;
import java.io.*;
class Function
{
public static void main (String[] args) throws java.lang.Exception
{
System.out.println(\"Enter number upto which you want function to compute: \");
int n = new Scanner(System.in).nextInt();
public static int fib(int n) {
{
if (n<=3)
return 0;
else {
sum=fib(n-3)+fib(n- 2)+fib(n-1);
for(int i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
sum=sum+i*j
}
return sum;
}
}
}
}

