Java
- Detalles
- Visto: 1361
import java.io.*;
public class ecuacion {
public static void main(String[] args){
int a=1, b=1, c=1;
double d, x1 = 0, x2 = 0;
String n;
try{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Valor de a:");
n = br.readLine();
a = Integer.parseInt(n);
System.out.println("Valor de b:");
n = br.readLine();
b = Integer.parseInt(n);
System.out.println("Valor de c:");
n = br.readLine();
c = Integer.parseInt(n);
}
catch(Exception e){
System.out.println("Error en los datos");
}
d = Math.pow(b,2)-4*a*c;
if (d > 0) {
x1 = (-b+Math.sqrt(d))/(2*a);
x2 = (-b-Math.sqrt(d))/(2*a);
System.out.println("Soluciones distintas " + x1 + " "+ x2 );
}
else if (d == 0){
x1 = (-b)/(2*a);
x2 = x1;
System.out.println("Solución doble " + x1 + " "+ x2 );
}
else {
System.out.println("no tiene solución");
}
}
}