Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- float calculos = 0.1f;
- boolean control = true;
- float x = 0;
- while (control){
- float margenDeError = 0.001f; // Margen de error
- for (int i = 0 ; i < 2 ; i++){ // check
- float izquierda = 2 + x; // Parte de la ecuacion
- float derecha = x * x; // Parte de la ecuacion
- float maxP = Math.max(Math.abs(izquierda), Math.abs(derecha));
- float minP = Math.min(Math.abs(izquierda), Math.abs(derecha));
- control = (maxP - minP > margenDeError);
- System.out.println(x);
- if (control && i == 0){
- x = -x;
- }else if (!control){
- System.out.println(x);
- break;
- }else{
- x = Math.abs(x);
- x += calculos;
- }
- }
- }
- }
- }
- Scanner teclado = new Scanner(System.in);
- teclado.useLocale(Locale.US); // o teclado.useLocale(Locale.FRANCE); para Europa
- System.out.println("Ingresa el operando izquierdo: ");
- float izquierdo = keyboard.nextFloat();
- System.out.println("Ingresa el operando derecho: ");
- float derecho = keyboard.nextFloat();
- import java.util.Scanner;
- class Test {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- float calculos = 0.1f;
- boolean control = true;
- float x = 0;
- float izquierda, derecha;
- Scanner teclado = new Scanner(System.in);
- teclado.useLocale(Locale.US);
- while (control) {
- float margenDeError = 0.001f; //Margen de error
- for (int i = 0; i < 2; i++) { //check
- System.out.print("Ingresa el operando izquierdo: ");
- izquierda = teclado.nextFloat();
- System.out.print("Ingresa el operando derecho: ");
- derecha = teclado.nextFloat();
- float maxP = Math.max(Math.abs(izquierda), Math.abs(derecha));
- float minP = Math.min(Math.abs(izquierda), Math.abs(derecha));
- control = (maxP - minP > margenDeError);
- System.out.printf("%gn", x);
- if (control && i == 0) {
- x = -x;
- } else if (!control) {
- System.out.println(x);
- break;
- } else {
- x = Math.abs(x);
- x += calculos;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment