Advertisement
lucas-canellas

exercicios-lista1-11

Jan 23rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package exercicio11;
  2. import java.util.Scanner;
  3.  
  4. public class MetodoBabilonico {
  5.    
  6.     public static void main(String[] args) {
  7.        
  8.         Scanner teclado = new Scanner(System.in);
  9.        
  10.         double limInferior = 0;
  11.         double limSuperior;
  12.         double erro;
  13.        
  14.         System.out.println("Insira a raiz: ");
  15.         limSuperior = teclado.nextDouble();
  16.         System.out.println("Insira o erro maximo:");
  17.         erro = teclado.nextDouble();
  18.        
  19.         double raiz = limSuperior;
  20.        
  21.         double chute = (limInferior+limSuperior)/2;
  22.        
  23.         while(Math.abs(chute - limInferior)>erro) {
  24.             if((chute*chute)<raiz) {
  25.                 limInferior = chute;
  26.             } else {
  27.                 limSuperior = chute;
  28.             }
  29.             chute = (limInferior+limSuperior)/2;
  30.         }
  31.        
  32.         System.out.println(chute);
  33.        
  34.        
  35.        
  36.        
  37.        
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement