Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- public class Roots
- {
- private double guess;
- private double a;
- private double n;
- private double epsilon;
- public Roots(double a, double n, double epsilon)
- {
- this.a = a;
- this.n = n;
- this.epsilon = epsilon;
- guess = 1;
- }
- public boolean hasMoreGuesses()
- {
- if((Math.abs(Math.pow(guess, n) - a)) < epsilon)
- return false;
- else
- return true;
- }
- public double nextGuess()
- {
- guess = (guess + a/guess)/2.0;
- return guess;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement