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
You are about to repair and change the resistor (small components),but the components are too small to solder and hold,what tool
exis [7]

Answer:

Needle-nose pliers

Explanation:

Required

Tool used to hold small components

The device to do this is the needle nose pliers.

This device has several functions, but it is specifically designed to hold small components in the computer when the computer is being repaired.

Among the other functions are:

  • Picking small and tiny screws
  • Cutting of wires
  • Hold wires against the side of the computer case
8 0
3 years ago
Which of the following statement about device formatting is FALSE?
notsponge [240]

Answer:

The correct option is;

A) Device manufacturers store the initial file-system data structures in the device.

Explanation:

Before a storage device can be used for data storage, it is required to prepare the device for use and to make the device to become visible to the operating system by formatting of the device

New storage devices are not pre-formatted or come with a ready to use file system as there are different file systems specifically designed for particular  operating systems or operating environment.

Formatting creates partitions, makes the hard drive visible to the operating system and creates a file system that is new such that the storage device can be used for storing files.

4 0
3 years ago
To indent the first line of a paragraph which key should you use
JulijaS [17]
You need to press the spacebar
3 0
4 years ago
Read 2 more answers
Select the correct answer.
saveliy_v [14]

Answer:

its TASCAM porta studio

Explanation: i got it right on edge

6 0
3 years ago
It can be hard to get close enough to photograph animals in the wild true or false
marysya [2.9K]

Answer:

True

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • Set numMatches to the number of elements in userValues (having NUM_VALS elements) that equal matchValue. Ex: If matchValue = 2 a
    6·1 answer
  • If you want to find out the specific questions you answered incorrectly on a particular examination, what option on the Web site
    6·1 answer
  • Which form of Internet access currently uses a technology called 4G?
    15·2 answers
  • Discuss whether the redundant data should be addressed prior to beginning the wireless network architecture project, in coordina
    11·1 answer
  • __________ systems support the search for and sharing of organizational expertise, decision making, and collaboration at the org
    9·1 answer
  • Pls help me with this pls
    7·2 answers
  • USE THIS CODE ON FETCH REWARDS FOR BRAINLIEST​ Also I will be doing a gift card giveaway for the ppl that use my code ​
    6·2 answers
  • Please describe the role of games in modern society!
    5·2 answers
  • If you use your computer primarily for telnet into a remote computer, will you have a large long distance telephone bill?
    14·1 answer
  • attackers typically use ack scans to get past a firewall or other filtering device. how does the process of an ack scan work to
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!