Guest User

Untitled

a guest
Dec 13th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. public class Test {
  2. /**
  3. * @param args the command line arguments
  4. */
  5.  
  6. public static void main(String[] args) {
  7.  
  8. float calculos = 0.1f;
  9. boolean control = true;
  10. float x = 0;
  11.  
  12. while (control){
  13. float margenDeError = 0.001f; // Margen de error
  14.  
  15. for (int i = 0 ; i < 2 ; i++){ // check
  16. float izquierda = 2 + x; // Parte de la ecuacion
  17. float derecha = x * x; // Parte de la ecuacion
  18.  
  19. float maxP = Math.max(Math.abs(izquierda), Math.abs(derecha));
  20. float minP = Math.min(Math.abs(izquierda), Math.abs(derecha));
  21. control = (maxP - minP > margenDeError);
  22. System.out.println(x);
  23.  
  24. if (control && i == 0){
  25. x = -x;
  26. }else if (!control){
  27. System.out.println(x);
  28. break;
  29. }else{
  30. x = Math.abs(x);
  31. x += calculos;
  32. }
  33. }
  34. }
  35. }
  36. }
  37.  
  38. Scanner teclado = new Scanner(System.in);
  39. teclado.useLocale(Locale.US); // o teclado.useLocale(Locale.FRANCE); para Europa
  40. System.out.println("Ingresa el operando izquierdo: ");
  41. float izquierdo = keyboard.nextFloat();
  42. System.out.println("Ingresa el operando derecho: ");
  43. float derecho = keyboard.nextFloat();
  44.  
  45. import java.util.Scanner;
  46.  
  47. class Test {
  48. /**
  49. * @param args the command line arguments
  50. */
  51. public static void main(String[] args) {
  52.  
  53. float calculos = 0.1f;
  54. boolean control = true;
  55. float x = 0;
  56. float izquierda, derecha;
  57. Scanner teclado = new Scanner(System.in);
  58. teclado.useLocale(Locale.US);
  59.  
  60. while (control) {
  61.  
  62. float margenDeError = 0.001f; //Margen de error
  63.  
  64. for (int i = 0; i < 2; i++) { //check
  65. System.out.print("Ingresa el operando izquierdo: ");
  66. izquierda = teclado.nextFloat();
  67. System.out.print("Ingresa el operando derecho: ");
  68. derecha = teclado.nextFloat();
  69.  
  70. float maxP = Math.max(Math.abs(izquierda), Math.abs(derecha));
  71. float minP = Math.min(Math.abs(izquierda), Math.abs(derecha));
  72. control = (maxP - minP > margenDeError);
  73. System.out.printf("%gn", x);
  74. if (control && i == 0) {
  75. x = -x;
  76. } else if (!control) {
  77. System.out.println(x);
  78. break;
  79. } else {
  80. x = Math.abs(x);
  81. x += calculos;
  82. }
  83. }
  84. }
  85. }
  86. }
Add Comment
Please, Sign In to add comment