Untitled
unknown
java
a year ago
1.1 kB
9
Indexable
import java.util.Scanner;
public class P1 {
public static void Sol(int a, int b, int c) {
int delta = b * b - 4 * a * c;
if (a != 0) {
if (delta > 0) {
float x1 = (float) (-b + Math.sqrt(delta)) / (2 * a);
float x2 = (float) (-b - Math.sqrt(delta)) / (2 * a);
System.out.println("x1 = " + x1 + " & x2 = " + x2);
} else if (delta == 0) {
System.out.println("Phuong trinh co nghiem kep: x = " + (-b * 1.0) / 2 * a);
} else {
System.out.println("Phuong trinh vo nghiem");
}
}
else {
if(b != 0) {
if(c != 0) {
System.out.println(-c * 1.0 / b);
}
else {
System.out.println("x = " + 0);
}
}
else {
System.out.println("Phuong trinh vo so nghiem");
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
Sol(a, b, c)
// Sol(x, n);
// if (Sol(n)) {
// System.out.println("YES");
// } else {
// System.out.println("NO");
// }
}
}Editor is loading...
Leave a Comment