JAVA编程:已知:s=1-1/2+1/3-1/4+…+1/(n-1)-1/n,编写程序求解n=100时的S值.(用JA

JAVA编程:已知:s=1-1/2+1/3-1/4+…+1/(n-1)-1/n,编写程序求解n=100时的S值.(用JAVA语言编写),程序哪
public class Exe45
{
public static void main(String args[])
{
double s=1.0000;
for(int i=1;i<=49;i++)
{
s=s+(1/(double)(2*i+1))-(1/(double)(2*i));
}
double sum=s-1/100;
System.out.println("s=1-1/2+...-1/100的和="+sum);
}
yiyang3 1年前 已收到3个回答 举报

pople2 幼苗

共回答了20个问题采纳率:95% 举报

楼主,运行了下你的程序 貌似没什么问题,我的:
public void col(){
double s=1;
for(int i=2;i

1年前

9

蜢钻 幼苗

共回答了3个问题 举报

public class Test {
public static void main(String args[]) {
System.out.println("s=1-1/2+...-1/100=" + count(100));
}
private static double count(int n) {
if (1 == n) {
return ...

1年前

0

tcj2004 幼苗

共回答了1个问题 举报

套高深了

1年前

0
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 19 q. 0.372 s. - webmaster@yulucn.com