Avatar of navyretired
navyretired
 asked on

Where is my math error?

I am trying to find the square root of 1000. I know my problem is in my math somewhere. I have treid a lot of stuff today but very little works.  Please provide some ideas of where I am making my mistake. This is classwork but to be honest I am about ready to turn it in as it is.

I NEED THE OUTPUT
Finding the square root of:1000

Pass:1 Est = 500.500000
Pass:2 Est = 251.249001
Pass:3 Est = 127.614558
Pass:4 Est = 67.725327
Pass:5 Est = 41.245426
Pass:6 Est = 32.745269
Pass:7 Est = 31.642016
Pass:8 Est = 31.622782
Pass:9 Est = 31.622777
Pass:10 Est = 31.622777
Pass:11 Est = 31.622777
Pass:12 Est = 31.622777
Pass:13 Est = 31.622777
Pass:14 Est = 31.622777
Pass:15 Est = 31.622777
Pass:16 Est = 31.622777

The square root of 1000 is 31.622777

I AM GETTING THIS AS A OUTPUT
Finding the square root of:1000

Pass:1 Est = 1000.000000
Pass:2 Est = 501.000000
Pass:3 Est = 252.496008
Pass:4 Est = 130.208463
Pass:5 Est = 72.784224
Pass:6 Est = 50.131353
Pass:7 Est = 45.013273
Pass:8 Est = 44.722306
Pass:9 Est = 44.721360
Pass:10 Est = 44.721360
Pass:11 Est = 44.721360
Pass:12 Est = 44.721360
Pass:13 Est = 44.721360
Pass:14 Est = 44.721360
Pass:15 Est = 44.721360
Pass:16 Est = 44.721360

The square root of 1000 is 44.721360
Process completed.



class squareRoot1
 
{
   public static void main(String args[])
    {
        int n = 1000;
        double est = n;
        est = n;
        System.out.println("Finding the square root of:"+n);
        System.out.println("");
 
        for(int i = 1; i < 17; i++)
 
        {
            System.out.printf("Pass:"+i+" Est = %1.6f\n",est);
            est = (n/est)+est/2;
        }
System.out.println("");
System.out.printf("The square root of 1000 is %1.6f",est);
    }
}

Open in new window

Java

Avatar of undefined
Last Comment
navyretired

8/22/2022 - Mon
navyretired

ASKER
Someone help me with this already................ Please disregard this post.
Mick Barry

try using all doubles

class squareRoot1
 
{
   public static void main(String args[])
    {
        double n = 1000.0;
        double est = n;
        est = n;
        System.out.println("Finding the square root of:"+n);
        System.out.println("");
 
        for(int i = 1; i < 17; i++)
 
        {
            System.out.printf("Pass:"+i+" Est = %1.6f\n",est);
            est = (n/est)+est/2.0;
        }
System.out.println("");
System.out.printf("The square root of 1000 is %1.6f",est);
    }
}
ASKER CERTIFIED SOLUTION
Thomas4019

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
navyretired

ASKER
Sorry Thomas I did try to delete this one but you guys are just to fast.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes