math类

package com.API;

import java.util.Scanner;

//Math数学类
public class TestMath {
public static void main(String[] args) {
//JDK看API文档 https://docs.oracle.com/javase/8/docs/api/
// System.out.println(Math.abs(-12));//abs获取绝对值
// System.out.println(Math.abs(12));
// System.out.println(Math.max(10,15));
// //pow 幂
// System.out.println(Math.pow(3,3));
// //round 四舍五入
// System.out.println(Math.round(4.5));
// //sqrt 求平方根
// System.out.println(Math.sqrt(9));
// //
System.out.println("请计算一元二次方程的根");
Scanner s1 = new Scanner(System.in);
while (true) {
System.out.println("请输入a");
double a = s1.nextInt();
System.out.println("请输入b");
double b = s1.nextInt();
System.out.println("请输入c");
double c = s1.nextInt();
double dt = Math.pow(b,2) - 4 * a * c;
if (dt < 0){
System.out.println("无解");
}else if (dt == 0){
System.out.println("次方程只有一个解");
double x = -b / (2*a);
System.out.println("x=" + x);
}else {
System.out.println("此方程有两个解");
double x1 = (-b + Math.sqrt(dt)) / (2*a);
double x2 = (-b - Math.sqrt(dt)) / (2*a);
System.out.println("x1的解为=" + x1 + " " + "x2的解为=" + x2);
}
}


}
}
posted @ 2022-05-13 09:58  小松2739  阅读(19)  评论(0编辑  收藏  举报