题目:求一元二次方程aX^2+bX+c=0的根。
package cn.wdl.demo;import java.util.Scanner;public class Case02 {public static void solution(double a,double b,double c) {double delta;double x1;double x2;delta = b*b-4*a*c;if(delta>=0) {if(delta>0) {x1=(-b+Math.sqrt(delta))/(2*a);x2=(-b-Math.sqrt(delta))/(2*a);}else{x1=x2= (-b/(2*a));}System.out.println("方程解为x1="+x1+",x2="+x2);}else {System.out.println("方程无解!");}}public static void main(String[] args) {// 2.求一元二次方程aX^2+bX+c=0的根double a=0;double b=0;double c=0;Scanner sc = new Scanner(System.in);System.out.println("请输入二次项系数:");a = sc.nextDouble();System.out.println("请输入一次项系数:");b = sc.nextDouble();System.out.println("请输入常数:");c = sc.nextDouble();solution(a,b,c);}}