蓝桥杯-调和级数

xiaoxiao2021-02-28  99

package 二〇一七年三月二十四日; public class 调和级数 { /*它是发散的,也就是说,只要加上足够多的项,就可以得到任意大的数字。 但是,它发散的很慢: 前1项和达到 1.0 前4项和才超过 2.0 前83项的和才超过 5.0 那么,请你计算一下,要加多少项,才能使得和达到或超过 15.0 呢?*/ public static void main(String[] args) { double sum=0d; for(int x=1;;x++){ sum+=1.0/x; System.out.println(sum); if(sum>=15.0){ System.out.println(x+"-----------------------------"); return; } } } }
转载请注明原文地址: https://www.6miu.com/read-68475.html

最新回复(0)