高普考題庫
108 年 108年公務人員高等考試三級考試暨普通考試・程式語言
申論 1閱讀以下Java 程式,列出數學式以說明變數e 在計算什麼?接著撰寫遞迴(recursive)程式public static double etx(int accuracy, int x)來計算前述變數e 的值,撰寫時必須使用etx 規定的參數與資料型態。(25 分)import java.util.Scanner;public class EtoX{public static void main( String[] args ){Scanner input = new Scanner( System.in );int number = 1;int accuracy;int factorial = 1;int x;double e = 1.0;double exponent = 1.0;x = input.nextInt();accuracy = input.nextInt();while ( number < accuracy ){exponent *= x;factorial *= number;e += exponent / factorial;number++;} // end while loopSystem.out.printf( "x: %d%ne: %f%n", x, e );} // end main} // end class EtoX