Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /**
- * Introduciendo tres valores (coeficientes de x², x y el término independiente) se dan
- * las soluciones de la ecuación de segundo grado.
- *
- * @author Carlos Gálvez
- * @version 07/12/2018
- */
- public class SegundoGrado {
- public static void main (String [] args) {
- Scanner input = new Scanner (System.in).useLocale(Locale.US);
- while (input.hasNext()) {
- int a = input.nextInt();
- int b = input.nextInt();
- int c = input.nextInt();
- if (a == 0) {
- if (b == 0){
- if (c == 0){
- System.out.printf("infinitas soluciones \n");
- } else {
- System.out.printf("indeterminado \n");
- }
- } else {
- System.out.printf(Locale.US, "%d %d %d %.4f de primer grado \n", a, b, c, ((double)-c/b));
- }
- } else if (b * b > 4 * a * c){
- double x1 = ((-b) + Math.sqrt(b * b - 4 * a * c))/(2 * a);
- double x2 = ((-b) - Math.sqrt(b * b - 4 * a * c))/(2 * a);
- System.out.printf(Locale.US, "%.4f y %.4f \n",x1,x2);
- } else if (b * b == 4 * a * c){
- System.out.printf(Locale.US, "%.4f doble \n", ((double)-b/2 * a));
- } else { //b² < 4ac
- double real = ((double) -b / (2 * a));
- double img = (Math.sqrt(Math.abs(b * b - 4 * a * c))) / 2 * a;
- System.out.printf(Locale.US, "%.4f + %.4fi y %.4f - %.4fi \n", real, img, real, img);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement