Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exercicio11;
- import java.util.Scanner;
- public class MetodoBabilonico {
- public static void main(String[] args) {
- Scanner teclado = new Scanner(System.in);
- double limInferior = 0;
- double limSuperior;
- double erro;
- System.out.println("Insira a raiz: ");
- limSuperior = teclado.nextDouble();
- System.out.println("Insira o erro maximo:");
- erro = teclado.nextDouble();
- double raiz = limSuperior;
- double chute = (limInferior+limSuperior)/2;
- while(Math.abs(chute - limInferior)>erro) {
- if((chute*chute)<raiz) {
- limInferior = chute;
- } else {
- limSuperior = chute;
- }
- chute = (limInferior+limSuperior)/2;
- }
- System.out.println(chute);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement