• API
• FAQ
• Tools
• Archive
daily pastebin goal
1%
SHARE
TWEET

# Untitled

a guest Dec 7th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import java.util.*;
2.
3. /**
4.  * Introduciendo tres valores (coeficientes de x², x y el término independiente) se dan
5.  * las soluciones de la ecuación de segundo grado.
6.  *
7.  * @author Carlos Gálvez
8.  * @version 07/12/2018
9.  */
11.     public static void main (String [] args) {
12.         Scanner input = new Scanner (System.in).useLocale(Locale.US);
13.         while (input.hasNext()) {
14.             int a = input.nextInt();
15.             int b = input.nextInt();
16.             int c = input.nextInt();
17.             if (a == 0) {
18.                 if (b == 0){
19.                     if (c == 0){
20.                         System.out.printf("infinitas soluciones \n");
21.                     } else {
23.                     }
24.                 } else {
25.                     System.out.printf(Locale.US, "%d  %d  %d  %.4f de primer grado \n", a, b, c, ((double)-c/b));
26.                 }
27.             } else if (b * b > 4 * a * c){
28.                 double x1 = ((-b) + Math.sqrt(b * b - 4 * a * c))/(2 * a);
29.                 double x2 = ((-b) - Math.sqrt(b * b - 4 * a * c))/(2 * a);
30.                 System.out.printf(Locale.US, "%.4f y %.4f \n",x1,x2);
31.             } else if (b * b == 4 * a * c){
32.                 System.out.printf(Locale.US, "%.4f doble \n", ((double)-b/2 * a));
33.             } else { //b² < 4ac
34.                 double real = ((double) -b / (2 * a));
35.                 double img = (Math.sqrt(Math.abs(b * b - 4 * a * c))) / 2 * a;
36.                 System.out.printf(Locale.US, "%.4f + %.4fi y %.4f - %.4fi \n", real, img, real, img);
37.             }
38.         }
39.     }
40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top