a006.
一元二次方程式
| From: [122.116.139.112] |
發表日期
:
2014-01-04 23:18
import java.util.Scanner;
public class JAVA {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
double Discriminant = Math.sqrt(b * b - 4 * a * c);
if (Discriminant > 0) {
int x1 = (int) (-b + Discriminant) / (2 * a);
int x2 = (int) (-b - Discriminant) / (2 * a);
System.out.println("Two different roots x1=" + x1 + " , " + "x2=" + x2);
} else if (Discriminant == 0) {
int x = (int) (-b + Discriminant) / (2 * a);
System.out.println("Two same roots x=" + x);
} else {
System.out.println("No real root");
}
}
}
}