Current location - Training Enrollment Network - Mathematics courses - Java mathematical equation input
Java mathematical equation input
Public static main(String[] arg0){

if(arg 0 = = null | | arg 0 . length = = 0){

System.out.println ("Please enter parameters: a, b, c");

system . exit(0);

}

for(int I = 0; I< arg0.length; i++){

Try {

float . parse float(arg 0[I]);

Catch (exception e){

System.out.println ("Please enter a number");

system . exit(0);

}

}

float a = float . parse float(arg 0[0]);

Floating point b = 0;;

Floating point c = 0;;

if(arg 0 . length & gt; = 2){

b = float . parse float(arg 0[ 1]);

}

if(arg 0 . length & gt; = 3){

c = float . parse float(arg 0[2]);

}

float tmp = b * b-4 * a * c;

if(tmp & lt; 0 ){

System.out.println("x has no real root ");

system . exit(0);

}

if(a = = 0 & amp; & ampb = = 0 & amp& ampc==0){

System.out.println("x has any real number root ");

system . exit(0);

}

Floating-point result = (-1) * b/(2 * a);

if(tmp == 0){

system . out . println(" x 1 = x2 = "+result ");

system . exit(0);

}

float x 1 =((- 1)* b+ Java . lang . math . sqrt(tmp))/(2 * a);

float x2 =((- 1)* b-Java . lang . math . sqrt(tmp))/(2 * a);

system . out . println(" x 1 = "+x 1 ");

system . out . println(" x2 = "+x2 ");

}