当前位置: 代码迷 >> 综合 >> HDOJ 1012 u Calculate e
  详细解决方案

HDOJ 1012 u Calculate e

热度:59   发布时间:2023-10-21 20:09:48.0

HDACM1012

注意输出格式即可。

import java.util.Scanner;public class Main{public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("n e");System.out.println("- -----------");double sum = 0;double j = 1;for (int i = 0; i <= 9; i++) {if (i==0) {sum = 1;System.out.println("0 1");continue;}j *= i;sum += 1.0/j;if (i==1) {System.out.println("1 2");}if (i==2) {System.out.println("2 2.5");}if (i>2) {System.out.printf("%d %.9f",i,sum);System.out.println();}}}
}