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
Landslides often accompany earthquakes and volcanoes and pose an additional threat to humans after these events.
xxTIMURxx [149]
I think the answer is tur
5 0
4 years ago
In a game with three frames, where will the objects on Layer 1 appear?
Ivan
It’s between d or c
6 0
3 years ago
Read 2 more answers
_____ consists of computer programs that govern the operation of a computer.
telo118 [61]
Hello <span>Siyujiang8092</span>

Answer: Software<span> consists of computer programs that govern the operation of a computer.

Hope that helps
-Chris</span>
6 0
4 years ago
What is a positive and negative interface of Apple, Microsoft, Linux GUI
Vsevolod [243]

Answer:

Microsoft is perfect the only negative is their tech support

Apple is AMAZING but their software is confusing and doesn't let you customize

Linux GUI its good but its way behind in its time

Explanation:

3 0
3 years ago
Read 2 more answers
Write a function isPrime of type int -&gt; bool that returns true if and only if its integer parameter is a prime number. Your f
PolarNik [594]

Answer:

import math

def isPrime(num):

 

   if num % 2 == 0 and num > 2:

       return False

   for i in range(3, int(math.sqrt(num)) + 1, 2):

       if num % i == 0:

           return False

   return True

Explanation:

The solution is provided in the python programming language, firstly the math class is imported so we can use the square root method. The first if statement checks if the number is even and greater than 2 and returns False since all even numbers except two are not prime numbers.

Then using a for loop on a range (3, int(math.sqrt(num)) + 1, 2), the checks if the number evenly divides through i and returns False otherwise it returns True

see code and output attached

5 0
4 years ago
Other questions:
  • Put the following numbers in order from greatest to least:
    13·1 answer
  • Gaven's instructor told him to include a personal statement in his work portfolio. Why did his instructor recommend including a
    8·1 answer
  • What is the post condition of an expression or variable
    11·1 answer
  • What does that program print out?<br><br> a) 2<br> b) 3<br> c) 4<br> d) 8
    14·2 answers
  • Give an example of at least one information system you know or have heard of.
    9·2 answers
  • In a multiprogramming and time-sharing environment, several users share the system simultaneously. This situation can result in
    9·1 answer
  • Is the flow of power reversible in a leadscrew?
    11·1 answer
  • What is the top 3 cloud provider in the world with statics or data including the example and reason(s).
    11·1 answer
  • A mesh network topology allows all computers to be directly connected. True or False
    9·1 answer
  • How can touch typing increase productivity of a business?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!