上传文件至 /
This commit is contained in:
40
javaclass.java
Normal file
40
javaclass.java
Normal file
@@ -0,0 +1,40 @@
|
||||
import java.util.Scanner;
|
||||
import java.lang.Math;
|
||||
class EquationRoot
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Scanner scan = new Scanner(System.in);
|
||||
double a,b,c,disc,x1,x2,p,q;
|
||||
|
||||
System.out.print("请输入系数a=");
|
||||
a = scan.nextDouble() ;
|
||||
|
||||
System.out.print("请输入系数b=");
|
||||
b = scan.nextDouble() ;
|
||||
|
||||
System.out.print("请输入系数c=");
|
||||
c = scan.nextDouble() ;
|
||||
|
||||
disc=b*b-4*a*c;
|
||||
|
||||
if ( Math.abs(disc) <= 1e-6 )
|
||||
System.out.println("x1=x2="+(-b/(2*a)));
|
||||
else
|
||||
{
|
||||
if(disc>1e-6)
|
||||
{
|
||||
x1=(-b+Math.sqrt(disc))/(2*a);
|
||||
x2=(-b-Math.sqrt(disc))/(2*a);
|
||||
System.out.printf("x1=%7.2f,x2=%7.2f\n", x1, x2);
|
||||
}
|
||||
else
|
||||
{
|
||||
p=-b/(2*a);
|
||||
q=Math.sqrt(Math.abs(disc))/(2*a);
|
||||
System.out.printf("x1=%7.2f + %7.2f i\n", p, q);
|
||||
System.out.printf("x2=%7.2f - %7.2f i\n", p, q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user