用迭代法求x=根号a,这个错在哪里?
1个回答
2018-10-28 · 知道合伙人互联网行家
关注
展开全部
public static void main(String[] args)
{
double a, x1, x2, b = 1;
Scanner sc=new Scanner(System.in);
a=sc.nextDouble();
x1 = a / 2;
while ( b >= 1e-5)
{
x2 = (x1 + a / x1) / 2;
b = Math.abs(x1 - x2);
x1 = x2;
}
System.out.println(x1);
}
{
double a, x1, x2, b = 1;
Scanner sc=new Scanner(System.in);
a=sc.nextDouble();
x1 = a / 2;
while ( b >= 1e-5)
{
x2 = (x1 + a / x1) / 2;
b = Math.abs(x1 - x2);
x1 = x2;
}
System.out.println(x1);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询