24.- OBTENER LAS RAICES REALES DE UNA ECUACIÓN DE SEGUNDO GRADO:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package problema024;
import java.io.*;
/**
*
* @author abel montalvan
*/
public class Problema024 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws IOException {
double a,b,c,d,x1,x2;
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("a: ");
a=(double) Integer.parseInt(in.readLine());
System.out.println("b: ");
b=(double)Integer.parseInt(in.readLine());
System.out.println("c: ");
c=(double) Integer.parseInt(in.readLine());
d = Math.pow(b,2)-4*c;
if(a!=0 && d>=0)
{
x1 = (-b+Math.pow(d,(1.0/2)))/2*a;
x2 = (-b-Math.pow(d,(1.0/2)))/2*a;
}
else
{
x1 = 0;
x2 = 0;
}
System.out.println("");
System.out.println("x1: " + x1);
System.out.println("x2: " + x2);
System.out.println();
}
}
No hay comentarios:
Publicar un comentario