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 @   小松2739  阅读(20)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示