So I wrote this code and I keep getting this error message:
Exception in
thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at BabylonianSquareRootVersionB.main(BabylonianSquareRootVersionB.java:11)
It's in the line *
String N = args[0];* but I can't figure out what's wrong with it. any help? Thank you so much.
This is what the final result is supposed to look like:
Enter the value for n: 10
Enter your guess: 100
n is 10.0
Final guess is 3.162277660168379
The estimation error is 4.440892098500626E-16
and these are the instructions:
The Babylonian algorithm to compute the square root of a positive number, n, is as follows:
a. Make a guess at the answer
b. Compute r= n/guess
c. Set guess = (guess + r)/2
d. Go back to step (b) for as many iterations as are necessary. The more you repeat steps (b) and (c), the closer
guess will become to the square root of n.
PART B: Write a second program (name it BabylonianSquareRootVersionB) that:
1. Prompts the user for values for n and for guess at runtime, and receives the user’s responses using
Scanner. Store the values as doubles.
2. As with the previous program, execute steps (b) and (c) 10 times and display the value of n, the final value
of guess and the difference between guess and the actual square root of n