Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is there any one who can help me in this program in java language. 1) Write the

ID: 3672919 • Letter: I

Question

Is there any one who can help me in this program in java language.

1) Write the recursive and nonrecursive version of a. Int factorial(int n), (use nfactorial as the name for non-recursive version) (where n >= 0) b. Int fibonacci(int n), (and nfibonacci as the name for non-recursive version)

2) Develop a testing scheme using at least 20 different values of n (from small to sufficiently large) and the time function to find the time spent for different values of n.

3. Combine all functions in one program (project) and send your output to a file named p5Out(yourName).txt or screen copy the output to a file named p5Out(yourName).docx.

Finally, combine all result into one word document and briefly summarize your finding into p5Recursion(yourName).docx.

4. Name your Java program p5Recursion.java.

Explanation / Answer

import java.util.*;
class fact_fibo
{
   int f0=1,f1=1,f2=2;

   void factorial(int x)
   {
       int f=1,i;

       for(i=1;i<=x;i++)
       {
           f=f*i;
       }
       System.out.println("Factorial ="+f);
   }
   int nfactorial(int x)
   {
       int f;
  
       if(x==1)
       {
           return (1);
       }
       else
       {
           f=x*rec(x-1);
       }
  
       return (f);
   }

  
   public void fibonacci(int n)
   {


       if(n>0)
       {
            f2 = f0 + f1;
            f0 = f1;
            f1= f2;
            System.out.println(f2);
            fibonacci(n-1);
       }
   }

   public void nfibonacci(int n)
   {
       int i;
       f1=1;
       f0=1;
       f2=0;      
       System.out.println("1"+" "+"1");
       for(i=1;i<=n-2;i++)
       {
           f2=f0+f1;
           System.out.println(" "+f2);
           f0=f1;
           f1=f2;
       }
   }
}

class p5Recursion
{
   public static void main(String args[])
   {

       int k,n;
       int i=0,j=1,f;
       fact_fibo o = new fact_fibo();

       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the range of the Fibonacci series: ");
       n=scan.nextInt();

       System.out.println("Fibonacci Series: ");
       System.out.println("1"+" "+"1");
       o.fibonacci(n);
       o.nfibonacci(n);
       o.factorial(n);
       int k= o.nfactorial(n);   
       System.out.println("Factorial is ="+k);
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote