Skip to content

Instantly share code, notes, and snippets.

@gmfc
Created May 9, 2013 11:15
Show Gist options
  • Select an option

  • Save gmfc/5546904 to your computer and use it in GitHub Desktop.

Select an option

Save gmfc/5546904 to your computer and use it in GitHub Desktop.
Metodo de Newton para raiz quadrada.
import java.util.*;
class prog{
public static void main(String [] args){
double xa,n,eps,xn;
Scanner s = new Scanner(System.in);
xa = s.nextDouble();
n = s.nextDouble();
eps = s.nextDouble();
xn = xa - (xa*xa-n)/(2*xa);
while(math.abs(xn-xa)>=eps){
xa = xn;
xn = xa -(xa*xa-n)/(2*xa);
}
system.out.println(xn);
}//main
}//prog
@gmfc
Copy link
Copy Markdown
Author

gmfc commented May 9, 2013

Da para otimizar o código com um único loop for.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment