-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
36 lines (26 loc) · 917 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.Locale;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Locale.setDefault(Locale.US);
Scanner scanner = new Scanner(System.in);
double coeficienteA, coeficienteB, coeficienteC;
double x1, x2, delta;
System.out.print("Coeficiente A: ");
coeficienteA = scanner.nextDouble();
System.out.print("Coeficiente B: ");
coeficienteB = scanner.nextDouble();
System.out.print("Coeficiente C: ");
coeficienteC = scanner.nextDouble();
delta = (coeficienteB * coeficienteB) - 4 * coeficienteA * coeficienteC;
if (delta >= 0) {
x1 = (-coeficienteB + Math.sqrt(delta)) / (2 * coeficienteA);
x2 = (-coeficienteB - Math.sqrt(delta)) / (2 * coeficienteA);
System.out.printf("x1: %.4f%n", x1);
System.out.printf("x2: %.4f",x2);
} else {
System.out.println("Esta equação não possui raízes reais!");
}
scanner.close();
}
}