2011-06-17 12:45:33Morris

[JAVA] a006. 一元二次方程式

/**********************************************************************************/
/*  Problem: a006 "一元二次方程式"                                         */
/*  Language: JAVA                                                                */
/*  Result: AC (122ms, 5984KB) on ZeroJudge                                       */
/*  Author: new1028 at 2011-06-17 09:26:40                                        */
/**********************************************************************************/


import java.util.Scanner;
import java.lang.Math.*;
public class a005 {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()) {
            double a, b, c, d;
            a = cin.nextDouble();
            b = cin.nextDouble();
            c = cin.nextDouble();
            d = b*b - 4*a*c;
            if(d > 0)
                System.out.println("Two different roots x1=" + (int)((-b+Math.sqrt(d))/(2*a)) + " , x2=" + (int)((-b-Math.sqrt(d))/(2*a)));
            else if(d == 0)
                System.out.println("Two same roots x=" + (int)(-b/(2*a)));
            else
                System.out.println("No real root");
        }
    }
}