public class Helloword {
public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
System.out.println("请输入二次幂参数:");
int a =scan.nextInt();
System.out.println("请输入一次幂参数:");
int b =scan.nextInt();
System.out.println("请输入c:");
int c =scan.nextInt();
System.out.println("方程为:"+a+"x^2+"+b+"x+"+c+"=0");
if(a==0&&b!=0){
int x;
x=-(b/c);
System.out.println("方程解为:"+x);
}else{
int d = (b*b-(4*a*c));
int f =(int)Math.sqrt(d);
if(d>0)
System.out.println("方程解为:"+(-b+f)/(2*a)+"和"+(-b-f)/(2*a));
else if(d<0)
System.out.println("方程解无解:");
else
System.out.println("方程解为:"+(-(b/(2*a))));
}
}
}
利用java解一元二次方程
最新推荐文章于 2023-08-25 10:31:53 发布