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

Write a Java program that has 3 Methods: The first method will be called CallFib

ID: 3735688 • Letter: W

Question

Write a Java program that has 3 Methods: The first method will be called CallFibor Fac It will receive a single string as a parameter. If the string is "Fib" it will call the second method called Fibonacci If the string is "Fac" it will call the third method called Factorial The Second method prints the first 10 numbers in the Fibonacci sequence. The Second method has a single integer as it's parameter, here we're going to pass it the value 10.The Third method prints the value of 10 factorial. The third method has a single integer as it's parameter, which te it what number to compute the factorial of. We want to make the second and third functions work for cases other than just the first 10 numbers so add a parameter to the Febonacci function and the Factorial function which will tell it how far to go along the Fibonacci sequence or the Factorial. Research what the Fibonacci sequence IS Research what a Factorial is. Write a Java program that has 3 Methods: The first method will be called CallFibor Fac It will receive a single string as a parameter. If the string is "Fib" it will call the second method called Fibonacci If the string is "Fac" it will call the third method called Factorial The Second method prints the first 10 numbers in the Fibonacci sequence. The Second method has a single integer as it's parameter, here we're going to pass it the value 10.The Third method prints the value of 10 factorial. The third method has a single integer as it's parameter, which te it what number to compute the factorial of. We want to make the second and third functions work for cases other than just the first 10 numbers so add a parameter to the Febonacci function and the Factorial function which will tell it how far to go along the Fibonacci sequence or the Factorial. Research what the Fibonacci sequence IS Research what a Factorial is.

Explanation / Answer

import java.io.*;
import java.util.*;
public class JavaProgram
{
static void compare(String s)
{
boolean b1=s.equals("Fib");
boolean b2=s.equals("Fac");
Scanner sc=new Scanner(System.in);
int n; n=sc.nextInt();
if(b1)
{
fibonaci(n);
}
if(b2)
{
factorial(n);
}
sc.close();
}
static void fibonaci(int k)
{
int a,b,c;
int i=3;
a=0;
b=1;
System.out.print(a+" "+b+" ");
c=a+b;
a=b;
b=c;
while(i<=k)
{
System.out.print(c+" ");
a=b;
b=c;
c=a+b;
i++;
}
}
static void factorial(int f)
{
int i=1;
long fact;
fact=1;
while(i<=f)
{
fact=fact*i;
i++;
}
System.out.println(fact);
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
compare(s);
}
}
F

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