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
In terms of CPU scheduling metrics, __________ is the time at which the job completes minus the time at which the job arrived in
Evgesh-ka [11]

Answer:

b. turnaround time

Explanation:

A scheduling computer system refers to the ability of the computer that typically allows one process to use the central processing unit (CPU) while another process is waiting for input-output (I/O), thus making a complete usage of any lost central processing unit (CPU) cycles in order to prevent redundancy.

In terms of CPU scheduling metrics, turnaround time is the time at which the job completes minus the time at which the job arrived in the system. It is one of the scheduling metrics to select for optimum performance.

7 0
2 years ago
College entrance requirements are the expectations for admission.
qwelly [4]

College entrance requirements are the expectations for admission.

O A. only

O B. least important

O C. maximum

O D. minimum

<h3>D.Minimum</h3>

College entrance requirements are the <u>minimum</u> expectations for admission.

6 0
3 years ago
Describe how to add slide numbers and image to a Microsoft power point presentations ?​
Dafna11 [192]
Oh we did this in class I know this
6 0
2 years ago
Jeffrey works with a huge database of spreadsheet records each day. To organize and identify these spreadsheets, he wants to ass
Reika [66]

Answer:

File details is the correct answer for PLATO users

8 0
2 years ago
Read 2 more answers
You are training to complete in a local 5K run. You record your time scores in minutes after completing seven practice runs. Wri
trapecia [35]

Answer:

Following are the program to this question:

#include <iostream>//defining header file

using namespace std;

float Avg(float sum, int n)//defining method Avg that accepts float parameter

{

float average=sum/n;//defining float variable average that holds average value  

return average;//return average

}

int main()//defining main method

{

float ar[ ] = {24.1,24.5,24.4,23.8,28.2,29.1,27.4};//defining float array

float sum;//defining float variable sum

int n=7,i;//defining integer variable  

for (i = 0; i <n; i++)//defining loop to count total of array

{

sum=sum+ar[i];//add value in sum variable

}

cout<<"The average is: "<<Avg(sum,n);//use print method to call and print method return value

return 0;

}

Output:

The average is: 25.9286

Explanation:

In the above code, the float method "Avg" is declared, that accepts two parameters, that is "sum and n", inside the method, a float variable average is declared that divides and returns its values.

In the main method a float array "ar" is declared that holds values, in the next line, float variable "sum" and integer variable "n, j" is used.

In for loop, the "i" variable is used to add array values in the sum variable and pass into cout to call the "Avg" method and print its return value.

3 0
2 years ago
Other questions:
  • To add text to a slide when using presentation software, you need to add a text box. To add a text box, click the Text Box butto
    6·2 answers
  • ____________________ is the premeditated, politically motivated attacks against information, computer systems, computer programs
    6·2 answers
  • You have no control over who views your social network information
    13·2 answers
  • What is the role of the federal government in regulating the media and the internet?
    6·2 answers
  • Data types influence the following in the workflow: (Select all that apply)a. the color choices and layout decisions around comp
    15·2 answers
  • If a client is found _________ the NAP will attempt to make it _______. Group of answer choices A. non-compliant, compliant B. s
    13·2 answers
  • Special words are those words that start and end with the same letter. [14]
    12·1 answer
  • The Arizona Department of Transportation has offices throughout the state. State documents are stored on a large server in a cen
    5·2 answers
  • Animals living in burrows under the ground is an interaction between the biosphere and the
    11·1 answer
  • [80 points] Fill in the missing word.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!