JAVA和数学的随意猜想01

今天吃饭时,想到1/2 + 1/3 + 1/6 = 1,于是想到分母从3,4开始,即1/3, 1/4, 第3个分母是前面两个分母的乘积,即 1/3 + 1/4 + ...... + 1/n,当n等于多少时,和为1呢?于是用代码去算:

int a = 3, b =4;

double sum = 0;

double  counts = 10000000000000000000000d;

for(int c = 0; c < counts; c++) {

c = a * b;

b= c;

System.out.println("c = " + c + "||" + "b = " + b);

sum = (1/a) + (1/b) +(1/c);

System.out.println("sum = " + sum);

if(sum == 1) {

System.out.println("c = " + c);

break;

}

}

}


public static void main(String[] args) {

guessfun();

}

}

结果是一直运算也得不到,然后一查,居然是调和级数的引用。

本文出自 “一鑫” 博客,请务必保留此出处http://8013881.blog.51cto.com/8003881/1379943

JAVA和数学的随意猜想01,布布扣,bubuko.com

JAVA和数学的随意猜想01

上一篇:C语言实现 二分查找数组中的Key值


下一篇:Java注解编程指南