90求助
查看原帖
90求助
1028188
xningi楼主2024/3/18 20:43
package 入门;

import java.util.Scanner;

public class B2053 {
	static Scanner sc = new Scanner(System.in);
	static double a, b, c;

	public static void main(String[] args) {
		a = sc.nextDouble();
		b = sc.nextDouble();
		c = sc.nextDouble();
		double drt = b * b - 4 * a * c;
		if (drt < 0) {
			System.out.println("No answer!");
		} else if (drt == 0) {
			System.out.printf("x1=x2=%.5f", (-b) / 2 * a);
		} else {
			double x1 = (-b + Math.sqrt(drt)) / (2 * a);
			double x2 = (-b - Math.sqrt(drt)) / (2 * a);
			if(x1 < x2) {
				System.out.printf("x1=%.5f;x2=%.5f", x1, x2);
			} else {
				System.out.printf("x1=%.5f;x2=%.5f", x2, x1);
			}
		}

	}

}

2024/3/18 20:43
加载中...