java+方法+一元二次方程求解

2024-11-18 11:19:02
推荐回答(1个)
回答1:

importjava.util.*;publicclassT5{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);doublea,b,c;doublex1,x2;System.out.print("请输入a:");a=in.nextInt();System.out.print("请输入b:");b=in.nextInt();System.out.print("请输入c:");c=in.nextInt();x1=((-b)+Math.sqrt(b*b-4*a*c))/(2*a);x2=((-b)-Math.sqrt(b*b-4*a*c))/(2*a);System.out.print("x1="+x1+"\tx2="+x2);}}