import java.util.Scanner;
public class Main {
public static double sqrt(double n) {
double x, y, eps = 0.000001;
x = n;
y = 1.0;
while(x - y > eps) {
x = (x + y) / 2;
y = n / x;
}
return x;
}
public static void NatureRootsQuadraticEquation( double a, double b, double c ) {
double S, P, Delta, x1, x2;
S = -b/a;
P = c/a;
Delta = b*b - 4*a*c;
System.
out.
println("\nVerify: "); if(Delta < 0) {
System.
out.
println("Imaginary"); } else {
x1 = (-b-sqrt(Delta))/(2*a);
x2 = (-b+sqrt(Delta))/(2*a);
System.
out.
printf("x1 = %.2f\n",x1
); System.
out.
printf("x2 = %.2f\n",x2
); if( S >= 0 ) {
if(P > 0) {
System.
out.
println("x1 > 0 positive, x2 > 0 positive"); } else if(P < 0){
System.
out.
println("x1 < 0 negative, x2 > 0 negative, |x1| < |x2|"); } else {
System.
out.
println("x1 = 0 ,x2 > 0"); }
//the S < 0 negative
} else {
if(P > 0) {
System.
out.
println("x1 < 0 positive, x2 < 0 negative"); } else if(P < 0){
System.
out.
println("x1 < 0 negative, x2 > 0 negative, |x1| > |x2|"); } else {
System.
out.
println("x1 = 0 ,x2 < 0"); }
}
}
}
public static void main
( String args
[] ) {
double a, b, c;
Scanner keyboard
= new Scanner
( System.
in ); if(args.length > 1){
a
= Double.
parseDouble(args
[0]); b
= Double.
parseDouble(args
[1]); c
= Double.
parseDouble(args
[2]); } else {
System.
out.
println("Give A, B, C for Ax^2 + Bx + C = 0: "); a = keyboard.nextDouble();
b = keyboard.nextDouble();
c = keyboard.nextDouble();
}
System.
out.
printf("The nature of the Roots Quadratic Equation: %.2fx^2 + %.2fx + %.2fc = 0", a, b, c
); NatureRootsQuadraticEquation(a,b,c);
}
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewoKICAgICAgIHB1YmxpYyBzdGF0aWMgZG91YmxlIHNxcnQoZG91YmxlIG4pIHsKICAgICAgICAgICAgICBkb3VibGUgeCwgeSwgZXBzID0gMC4wMDAwMDE7CiAgICAgICAgICAgICAgeCA9IG47CiAgICAgICAgICAgICAgeSA9IDEuMDsKICAgICAgICAgICAgICB3aGlsZSh4IC0geSA+IGVwcykgewogICAgICAgICAgICAgICAgeCA9ICh4ICsgeSkgLyAyOwogICAgICAgICAgICAgICAgeSA9IG4gLyB4OwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICByZXR1cm4geDsKICAgICAgIH0KCiAgICAgICBwdWJsaWMgc3RhdGljIHZvaWQgTmF0dXJlUm9vdHNRdWFkcmF0aWNFcXVhdGlvbiggZG91YmxlIGEsIGRvdWJsZSBiLCBkb3VibGUgYyApIHsKCiAgICAgICAgICAgICAgZG91YmxlIFMsIFAsIERlbHRhLCB4MSwgeDI7CgogICAgICAgICAgICAgIFMgPSAtYi9hOwogICAgICAgICAgICAgIFAgPSBjL2E7CiAgICAgICAgICAgICAgRGVsdGEgPSBiKmIgLSA0KmEqYzsKICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIlxuVmVyaWZ5OiAiKTsKICAgICAgICAgICAgICBpZihEZWx0YSA8IDApIHsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiSW1hZ2luYXJ5Iik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHgxID0gKC1iLXNxcnQoRGVsdGEpKS8oMiphKTsKICAgICAgICAgICAgICAgIHgyID0gKC1iK3NxcnQoRGVsdGEpKS8oMiphKTsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRmKCJ4MSA9ICUuMmZcbiIseDEpOwogICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGYoIngyID0gJS4yZlxuIix4Mik7CiAgICAgICAgICAgICAgICBpZiggUyA+PSAwICkgewogICAgICAgICAgICAgICAgICAgIGlmKFAgPiAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJ4MSA+IDAgcG9zaXRpdmUsIHgyID4gMCBwb3NpdGl2ZSIpOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZihQIDwgMCl7CiAgICAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJ4MSA8IDAgbmVnYXRpdmUsIHgyID4gMCBuZWdhdGl2ZSwgfHgxfCA8IHx4MnwiKTsKICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigieDEgPSAwICx4MiA+IDAiKTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAvL3RoZSBTIDwgMCBuZWdhdGl2ZQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgaWYoUCA+IDApIHsKICAgICAgICAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJ4MSA8IDAgcG9zaXRpdmUsIHgyIDwgMCBuZWdhdGl2ZSIpOwogICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoUCA8IDApewogICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIngxIDwgMCBuZWdhdGl2ZSwgeDIgPiAwIG5lZ2F0aXZlLCB8eDF8ID4gfHgyfCIpOwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIngxID0gMCAseDIgPCAwIik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICB9CgogICAgICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oIFN0cmluZyBhcmdzW10gKSB7CgogICAgICAgICAgICAgIGRvdWJsZSBhLCBiLCBjOwogICAgICAgICAgICAgIFNjYW5uZXIga2V5Ym9hcmQgPSBuZXcgU2Nhbm5lciggU3lzdGVtLmluICk7CiAgICAgICAgICAgICAgaWYoYXJncy5sZW5ndGggPiAxKXsKICAgICAgICAgICAgICBhID0gRG91YmxlLnBhcnNlRG91YmxlKGFyZ3NbMF0pOwogICAgICAgICAgICAgIGIgPSBEb3VibGUucGFyc2VEb3VibGUoYXJnc1sxXSk7CiAgICAgICAgICAgICAgYyA9IERvdWJsZS5wYXJzZURvdWJsZShhcmdzWzJdKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkdpdmUgQSwgQiwgQyBmb3IgQXheMiArIEJ4ICsgQyA9IDA6ICIpOwogICAgICAgICAgICAgIGEgPSBrZXlib2FyZC5uZXh0RG91YmxlKCk7CiAgICAgICAgICAgICAgYiA9IGtleWJvYXJkLm5leHREb3VibGUoKTsKICAgICAgICAgICAgICBjID0ga2V5Ym9hcmQubmV4dERvdWJsZSgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgICAgU3lzdGVtLm91dC5wcmludGYoIlRoZSBuYXR1cmUgb2YgdGhlIFJvb3RzIFF1YWRyYXRpYyBFcXVhdGlvbjogJS4yZnheMiArICUuMmZ4ICsgJS4yZmMgPSAwIiwgYSwgYiwgYyk7CiAgICAgICAgICAgICAgTmF0dXJlUm9vdHNRdWFkcmF0aWNFcXVhdGlvbihhLGIsYyk7CiAgICAgICB9Cn0K