u Calculate e
1 public class Main{ 2 public static void main(String args[]) { 3 System.out.println("n e\r\n" + 4 "- -----------"); 5 for(int i=0;i<10;i++) { 6 System.out.print(i+" "); 7 if(i==0) { 8 System.out.println(1); 9 continue; 10 } 11 if(i==1) { 12 System.out.println(2); 13 continue; 14 } 15 if(i==2) { 16 System.out.println(2.5); 17 continue; 18 } 19 double sum=1; 20 double mul=1; 21 for(int j=2;j<=i;j++) { 22 mul*=j; 23 sum+=1/mul; 24 } 25 sum+=1; 26 System.out.printf("%.9f",sum); 27 System.out.println(); 28 } 29 } 30 }