My favorites
▼
|
Sign in
lineadecodigo
Web Code Samples in spanish
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
lineadecodigo_java
/
src
/
com
/
lineadecodigo
/
java
/
basico
/
FactorialDeUnNumero.java
r478
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.lineadecodigo.java.basico;
/**
* @file FactorialDeUnNumero.java
* @version 1.0
* @author Linea de Codigo (http://lineadecodigo.com)
* @date 27.marzo.2011
* @url http://lineadecodigo.com/java/factorial-de-un-numero/
* @description Calculo de un factorial
*/
public class FactorialDeUnNumero {
public static int factorial(int x){
// Factorial recursivo
if (x==1)
return 1;
else
return x * factorial(x-1);
}
public static void main(String[] args) {
// Numero del que queremos sacar el factorial
int iNumero = 4;
int iFactorial = 1;
int iContador = iNumero;
while (iContador != 0) {
iFactorial = iFactorial * iContador;
iContador--;
}
System.out.println("El factorial del número " + Integer.toString(iNumero) + " es " + Integer.toString(iFactorial)); ;
System.out.println("El factorial del número " + Integer.toString(iNumero) + " es " + Integer.toString(factorial(iNumero)));
}
}
Show details
Hide details
Change log
r359
by vcuervo on Mar 26, 2011
Diff
Factorial de un número
Go to:
.../basico/FactorialDeUnNumero.java
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1016 bytes, 40 lines
View raw file
Powered by
Google Project Hosting