用JAVA的For循环编写1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10

日期:2018-04-09 19:55:32 人气:1

用JAVA的For循环编写1+1/2+1/3+1/4+1/5+1/6+1/7+1/8+1/9+1/10

class jia{ public static void main(String[] args){ float sum = 0; for (int i = 1;i <= 100;i++) { sum+=(float)1/i; } System.out.println(sum); } } 我把上面的哥们的东西改了下,估计更好看一些!运行没错。
    A+
热门评论