HDOJ 2011 多项式求和

来源:互联网 发布:单片机智能反编译器 编辑:程序博客网 时间:2024/05/21 17:59
/** * 多项式求和,注意输出格式 * Created by YangYuan on 2017/12/8. */public class Problem2011{    public static void main(String[] args)    {        DecimalFormat df = new DecimalFormat("0.00");        Scanner scanner = new Scanner(System.in);        int m = scanner.nextInt();        for (int i = 0; i < m; i++)        {            int x = scanner.nextInt();            double sum = 0;            for (int j = 1; j <= x; j++)            {                if (j % 2 != 0)                    sum += 1F / j;                else                    sum -= 1F / j;            }            System.out.println(df.format(sum));        }    }}
原创粉丝点击