1. Pedir los coeficientes de una ecuación se 2º grado, y muestre sus soluciones reales. Si no existen, debe indicarlo.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg2dogrado;
import java.util.Scanner;
/**
*
* @author MoWz
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner intro=new Scanner(System.in);
double a=0;
double b=0;
double x1;
double x2;
//ax^2+bx+c=0
System.out.println("ingrese el coeficiente A");
a=intro.nextDouble();
System.out.println("ingrese el coeficiente B");
b=intro.nextDouble();
if(Math.pow(b, 2) - 4 * a * b >=0)
{
x1=(-b + Math.sqrt(Math.pow(b, 2) - 4 * a * b)) / (2 * a);
x2=(-b - Math.sqrt(Math.pow(b, 2) - 4 * a * b)) / (2 * a);
System.out.println("x1 es igual a: "+x1);
System.out.println("x2 es igual a; "+x2);
}else
{
System.out.println("soluciones complejas");
}
// TODO code application logic here
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package pkg2dogrado;
import java.util.Scanner;
/**
*
* @author MoWz
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner intro=new Scanner(System.in);
double a=0;
double b=0;
double x1;
double x2;
//ax^2+bx+c=0
System.out.println("ingrese el coeficiente A");
a=intro.nextDouble();
System.out.println("ingrese el coeficiente B");
b=intro.nextDouble();
if(Math.pow(b, 2) - 4 * a * b >=0)
{
x1=(-b + Math.sqrt(Math.pow(b, 2) - 4 * a * b)) / (2 * a);
x2=(-b - Math.sqrt(Math.pow(b, 2) - 4 * a * b)) / (2 * a);
System.out.println("x1 es igual a: "+x1);
System.out.println("x2 es igual a; "+x2);
}else
{
System.out.println("soluciones complejas");
}
// TODO code application logic here
}
}
Holi
ResponderEliminarCreo que esta mal, falta un tercer valor (c) en la ecuación. Pero vamos no tengo ni idea...