-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactorial.java
More file actions
36 lines (32 loc) · 755 Bytes
/
Factorial.java
File metadata and controls
36 lines (32 loc) · 755 Bytes
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
public class Factorial {
public static long factorial(long n) {
if(n<=1) {
return 1;
}else {
return n*factorial(n-1);
}
}
public static long fibonacci(long n) {
if(n==0 || n==1) {
return 1;
}else {
return fibonacci(n-1)+fibonacci(n-2);
}
}
public static void main(String []args) {
/*
* Overflow en byte
*/
byte b=(byte)127;
byte c=(byte)10;
b+=c;
//System.out.println(c);
//System.out.println("El numero factorial de: 6 es: "+factorial(6));
long f=42;
long iniTime= System.nanoTime();
long n=fibonacci(f);
long finTime= System.nanoTime();
System.out.println("Se resolvio en "+(finTime-iniTime)/1000000000.0 +" segundos");
System.out.println("El numero fibonacci de "+f+" es: "+n);
}
}