Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Made in java! ! Input three integers from the keyboard, which are the values of A, B and C in the unary quadratic equation ax2+bx+c=0, and judge whether this equation has real roots.
Made in java! ! Input three integers from the keyboard, which are the values of A, B and C in the unary quadratic equation ax2+bx+c=0, and judge whether this equation has real roots.
The following program passed the test in jdk5.0.

Import java.util.scanner;

Common class test {

//the solution of a quadratic equation with one variable

Private static X fx (int a, int b, int c) throws an exception {

X X = new X();

Double m = b * b-4 * a * c;;

If (m & gt=0){

x . x 1 =(- 1 * b+ math . sqrt(m))/(2 * a);

x . x2 =(- 1 * b-math . sqrt(m))/(2 * a);

Returns x;

}

Otherwise, a new exception ("no solution") is thrown;

}

Public static void main(String[] args) {

Try {

//input parameters a, b, c

Scanner CIN = new scanner (system. in);

system . out . print(" a = ");

int a = CIN . nextint();

system . out . print(" b = ");

int b = CIN . nextint();

system . out . print(" c = ");

int c = CIN . nextint();

//calculation

X x=fx(a,b,c);

//Display

system . out . println(" \ n 1x 1 = "+x . x 1+" \ nx2 = "+x . x2);

}catch (exception e){

system . out . println(e . getmessage());

}

}

}

//The packing class of solution set of quadratic equation in one variable

Class x {

Double x1;

Double x2;

}