Ce diaporama a bien été signalé.
Le téléchargement de votre SlideShare est en cours. ×

# on java The following method is an example of what- What are the two c.docx

Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité
Publicité  Chargement dans…3
×

## Consultez-les par la suite

1 sur 2 Publicité

# on java The following method is an example of what- What are the two c.docx

on java
The following method is an example of what? What are the two components required for these types of methods?
Solution
The given program is an example of recursion method in java.
The factorial of a number be found using recursion also. The base case can be taken as the factorial of the number 0 or 1, both of which are 1. The factorial of some number n is that number multiplied by the factorial of (n-1). Mathematically,
factorial ( 0 ) = 1
factorial ( n ) = n * factorial ( n - 1 )
Given below is a program which calculates the factorial of 7 using recursion.the components required for this are as follows:
public class Factorial { // Here the class name is taken as Factorial

public static void main(String[] args) {
int n = 7; // initializing value of n
int result = factorial(n); // factorial value is stored in result
System.out.println(\"The factorial of 7 is \" + result); // printing the factorial value of 7
}

public static long factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
.

on java
The following method is an example of what? What are the two components required for these types of methods?
Solution
The given program is an example of recursion method in java.
The factorial of a number be found using recursion also. The base case can be taken as the factorial of the number 0 or 1, both of which are 1. The factorial of some number n is that number multiplied by the factorial of (n-1). Mathematically,
factorial ( 0 ) = 1
factorial ( n ) = n * factorial ( n - 1 )
Given below is a program which calculates the factorial of 7 using recursion.the components required for this are as follows:
public class Factorial { // Here the class name is taken as Factorial

public static void main(String[] args) {
int n = 7; // initializing value of n
int result = factorial(n); // factorial value is stored in result
System.out.println(\"The factorial of 7 is \" + result); // printing the factorial value of 7
}

public static long factorial(int n) {
if (n == 0) {
return 1;
} else {
return n * factorial(n - 1);
}
}
}
.

Publicité
Publicité

### on java The following method is an example of what- What are the two c.docx

1. 1. on java The following method is an example of what? What are the two components required for these types of methods? Solution The given program is an example of recursion method in java. The factorial of a number be found using recursion also. The base case can be taken as the factorial of the number 0 or 1, both of which are 1. The factorial of some number n is that number multiplied by the factorial of (n-1). Mathematically, factorial ( 0 ) = 1 factorial ( n ) = n * factorial ( n - 1 ) Given below is a program which calculates the factorial of 7 using recursion.the components required for this are as follows: public class Factorial { // Here the class name is taken as Factorial public static void main(String[] args) { int n = 7; // initializing value of n int result = factorial(n); // factorial value is stored in result System.out.println("The factorial of 7 is " + result); // printing the factorial value of 7 } public static long factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n - 1); } } }