Skip to content

Instantly share code, notes, and snippets.

@onlyangel
Created September 2, 2011 05:23
Show Gist options
  • Save onlyangel/1187973 to your computer and use it in GitHub Desktop.
Save onlyangel/1187973 to your computer and use it in GitHub Desktop.
sum n!/n^n, n=1 to infinity
public class T2 {
public static void main(String arg[]){
double acum = 0;
for (int n = 1;n<=10;n++){
acum+=factorial(n)/nALaN(n,n);
}
System.out.print(acum);
}
public static Long factorial(int i){
if (i==1){
return new Long(1);
}else{
return i*factorial(i-1);
}
}
public static double nALaN(int i, int n){
if (i==1){
return n;
}else{
return n*nALaN(i-1,n);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment