ALGORITMO RESOLVER ECUACION DE SEGUNDO GRADO CODIGO EN JAVA
CODIGO FUENTE
package vista;import java.util.Scanner;public class Principal { public static void main(String[] args) { Scanner t=new Scanner(System.in); double a,b,c,d,x1,x2; System.out.println ("Ingrese El Coeficiente de A"); a = t.nextDouble(); System.out.println ("Ingrese El Coeficiente de B"); b = t.nextDouble(); System.out.println ("Ingrese El Coeficiente de C"); c = t.nextDouble(); d = ((b*b)-(4*(a*c))); if (d < 0) { System.out.println ("La Ecuacion no tiene soluciones reales"); } if (d == 0) { System.out.println ("La ecuacion tiene solo una raiz real"); x1 = (-b)/(2*a); System.out.println ("La Solucion es, \nX1=X2 : " +x1); } if (d > 0) { System.out.println ("La ecuacion tiene dos raizes reales"); x1 = (-b)+Math.sqrt(d)/(2*a); x2 = (-b)-Math.sqrt(d)/(2*a); System.out.println ("La Solucion es \nX1 = " +x1+ "\n y, X2 = " +x2);} } }
Comentarios
Publicar un comentario