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]
3 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]3 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
PLEASE HURRY!!<br> Look at the image below
levacccp [35]
Answer is power and base

Explanation: both power and base are number variables
8 0
2 years ago
Is anyone else recieving a notification from brainly near the search bar about a message and click it and there nothing there???
Yakvenalex [24]

tessa the same with me I hate it and then I'll click I and then it's blank

4 0
3 years ago
How many pictures can a 32 mb memory card hold?
nasty-shy [4]
This depends on the number of pixels are in each picture. hope this helps.
7 0
3 years ago
Suppose two hosts, A and B, are connected by a 10 Mbps link. The length of a packet is 12 Kb (Kilobits, i.e., 12 × 103 bits). Th
Alekssandra [29.7K]

Answer:

Answer is provided in the explanation section

Explanation:

Given data:

Bandwidth of link = 10* 106 bps

Length of packet = 12* 103 bits

Distance of link = 40 * 103m

Transmission Speed = 3 * 108 meters per second  

Formulas:

Transmission Delay = data size / bandwidth = (L /B) second

Propagation Delay = distance/transmission speed = d/s

Solution:

Transmission Delay = (12* 103 bits) / (10* 106 bps) = 0.0012 s = 1.2 millisecond

Propagation Delay = (40 * 103 meters)/ (3 * 108mps) = 0.000133 = 0.13 millisecond

4 0
3 years ago
1) Create a class called Villain. Specifically, a Villain has the following fields: .name (String)
g100num [7]

Answer:

Explanation:

The following code is written in Java and creates both of the classes as requested with their variables and methods as needed. The crazyVillain class extends the Villain class and implements and overrides the needed variables and methods. Due to technical reasons, I have added the code as a txt file below.

7 0
3 years ago
Other questions:
  • Recall that with the CSMA/CD protocol, the adapter waits K. 512 bit times after a collision, where K is drawn randomly. a. For f
    5·1 answer
  • During the processing stage what does the computer do
    12·1 answer
  • The first character of the VIN designates which of the following? 
    15·2 answers
  • How is sharepoint used in organization today?
    12·1 answer
  • This is a free point thing!! I am giving 100 points!! Anyone wanna talk!!!!
    11·2 answers
  • Data warehousing and data mining mean the same thing when applied to CRM
    7·2 answers
  • Free 100 point to first to answer
    5·2 answers
  • What is percent encoding and why is it used?
    10·1 answer
  • How to unlock your iphone when you forgot the password?.
    15·1 answer
  • Assume you have a button control named btndisplaylist. Which is the default name for an event procedure that will be executed wh
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!