修正程序错误 计算:1-1/2+1/3-1/4...-1/50
//本人系初学这,还有请各位大虾帮忙解决下,多谢//计算1-1/2+1/3-1/4...-1/50的值
public class Three
{
static float suzi(int x)
{
float s;
if(x%2==0)
{s=-1/x;}
else
{s=1/x;}
return(s);
}
public static void main(String ags[])
{
int n;
float sum=0f;
for(n=1;n<=50;n++)
{sum=sum+suzi(n);}
System.out.println("所求和为:"+sum);
}
}