java

chenlong 发表于 1年前 · 关联问题 一元二次方程求解

import java.util.Scanner;

public class Main {

public static void main(String[] args) { Scanner scanner = new Scanner(System.in); float arr[] = new float[3]; for (int i = 0;i< 3;i++){ arr[i] = scanner.nextFloat(); } float a = arr[0]; float b = arr[1]; float c = arr[2]; if (Math.pow(b,2)-4*a*c>0){ System.out.println("YES"); Double bb = ((-b+Math.sqrt(b*b-4*a*c))/2*a); System.out.printf("%.6f",bb); System.out.println(); double cc = ((-b-Math.sqrt(b*b-4*a*c))/2*a); System.out.printf("%.6f",cc); }else if (Math.pow(b,2)-4*a*c==0){ System.out.println("YES"); float aa = (float) ((-b)/2*a); System.out.printf("%.6f",aa); System.out.println(); float dd = (float) (-b/2*a); System.out.printf("%.6f",dd); }else { System.out.println("NO"); } }

}