1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bezimeni [28]
4 years ago
13

1. Implement a method factorial(int n), that takes a number (int) and returns its factorial. Factorial of an integer is the prod

uct of all positive integers less than or equal to it. Method needs to be implemented using recursion.
Computers and Technology
1 answer:
marysya [2.9K]4 years ago
6 0

Answer:

import java.io.*;

import java.util.*;

public class Main

{

public static int factorial(int n){

if (n == 0)

return 1;    

else

return(n * factorial(n-1)); //recursively calling factorial function

}

public static void fibbonaci(int n)

{

if(n>0)

{

c=a+b; //next term in series

a=b;

b=c;

System.out.print(" "+c);    

fibbonaci(n-1); //recursively calling fibbonaci function

}

}

static int a=0,b=1,c;

  public static void main(String[] args) {

  int list_num,fact;

      List<Integer> num=Arrays.asList(1,3,5,7,9); //arraylist with 1,3,5,7,9

      for(Integer i:num) //for-each loop

      {    

      a=0;

      b=1;

      list_num=i.intValue();

      System.out.println("Fibbonaci series for "+list_num);

      System.out.print(a+" "+b);

      fibbonaci(list_num-2); //calling fibbonaci for values in list

      fact=factorial(list_num); //calling factorial for values in list

      System.out.println();

      System.out.println("Factorial for "+list_num+" is "+fact);

      System.out.println();

     

      }

  }

}

You might be interested in
The type of e-cards that have an antenna built into them are __________ cards.
maw [93]
Contactles..........................................................
3 0
3 years ago
Read 2 more answers
Robot is an example of which generation computer?​
n200080 [17]

Robot is an example of Fifth Generation Computer.

I hope it's help you...

Thanks♥♥

6 0
3 years ago
The item in this illustration that is highlighted is the _____. quick access tool bar view buttons status bar zoom control
tiny-mole [99]

Answer: scrollbar

Explanation:

7 0
3 years ago
Read 2 more answers
Which of the following describes how modern operating systems function?: A
sertanlavr [38]

Answer:

Try B

Explanation:

6 0
3 years ago
Design and implement an application that uses dialog boxes to obtain two integer values (one dialog box for each value) and disp
dybincka [34]

Answer: hey

Explanation:

7 0
3 years ago
Other questions:
  • For Adults/Adolescents, you should call/activate EMS: Before providing CPR. After providing CPR for 2 minutes. After an AED has
    13·1 answer
  • What is the circular motion that the earth makes in its orbit around the sun
    14·1 answer
  • What three components should be included in a computer that is used to create TV commercials and music videos? (Choose three.
    15·2 answers
  • Sandra wants to have her new technology up and running as soon as possible. She is looking for a tool that she can
    8·1 answer
  •  In which part of a professional email should you try to be brief, but highly descriptive? 
    10·1 answer
  • What is one potential problem with the following loop? System.out.print("Enter integers. Enter -1 to exit."); System.out.println
    12·1 answer
  • I'm working on an assignment for my computer science class (Edhesive) and when I run the code, there are no errors. But when I t
    11·1 answer
  • Is this statement true or false? While in slide show mode, if you are not careful you can close the application by clicking the
    10·1 answer
  • How to add a legend to a graph in excel?
    7·2 answers
  • In which cipher method are values rearranged within a block to create the ciphertext?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!