a006.
一元二次方程式
| From: [1.175.162.41] |
發表日期
:
2013-05-29 14:24
import java.util.Scanner;
public class a006{
public static void main(String[] args){
Scanner jin = new Scanner(System.in);
int a=0,b=0,c=0;//judge判斷的意思 用來公式解判斷式名稱
double judge=0,box=0,x1=0,x2=0;
while(jin.hasNext()){
a=jin.nextInt();
b=jin.nextInt();
c=jin.nextInt();
judge=Math.pow(b,2)-4*a*c;
x1=(-b+Math.sqrt(judge))/2*a;
x2=(-b-Math.sqrt(judge))/2*a;
System.out.printf("%f %f %f",x1,x2,judge);//檢查x1,x2,judge值是否有誤
if(x1==-0){
x1=0;
}
else if(x2==-0){
x2=0;
}
else if(x1<x2){
box=x1;
x1=x2;
x2=box;
}
else if(judge>=0){
if(judge==0)
System.out.printf("Two same roots x=%.0f\n",x1);
else
System.out.printf("Two different roots x1=%.0f , x2=%.0f\n",x1,x2);
}
else{
System.out.println("No real root");
}
}
}
}