This problem is very simple, mainly to understand the test instructions and pay attention to the output:
The complete result of the output is as follows:
N e------------0 11 22 2.53 2.6666666674 2.7083333335 2.7166666676 2.7180555567 2.7182539688 2.7182787709 2.718281526
The Java code is as follows:
ImportJava.util.*;ImportJava.io.*; Public classmain{ Public Static voidMain (string[] arg) {Scanner Scan=NewScanner (NewBufferedinputstream (system.in)); System.out.println ("N E"); System.out.println ("- -----------"); for(inti = 0; I! = 10; i + +){ if(i<2) {System.out.println (i+ " " + (int) Gete (i)); }Else if(i<3) {System.out.println (i+ " " +Gete (i)); }Else{System.out.printf ("%d%.9f", I,gete (i)); System.out.println (); }} scan.close (); } Static DoubleGete (intFrom ) { DoubleE = 0; if(from = = 0) {e=1; }Else{ while(from!=0) {e= e + 1.0/getproduct (from); from--; } e+=1; } returne; } Static intGetProduct (intFrom ) { intP=1; while(From! = 0) {p*=From ; from--; } returnp; }}
hdoj-acm1012 (JAVA)