栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Math类

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Math类

Math类 源码位置

rt.jar/java.lang包下

源码类
public final class Math
认识
Math类
概念:表示数学操作类
类方法:
		绝对值方法:		abs
		最大小方法:		max,min
		随机小数方法:	random
		四舍五入方法:	round
		平方根方法:		sqrt
		平方方法:		pow
		向下取整方法:	floor,floorDiv,floorMod
		三角函数方法:	sin,cos等

这里只介绍其中部分常用方法

类方法
public static int abs(int a)
public static int max(int a, int b)
public static int min(int a, int b)
public static double random()
public static int round(float a)  
public static double sqrt(double a)
public static double pow(double a, double b)
public static double floor(double a)
public static int floorDiv(int x, int y)
public static int floorMod(int x, int y)
例子
System.out.println(Math.PI);

System.out.println(Math.abs(-23));

System.out.println(Math.max(2, 5));

System.out.println(Math.min(2, 5));

System.out.println(Math.random());

System.out.println(Math.round(1.5f));

System.out.println(Math.sqrt(4));

System.out.println(Math.pow(2, 3));

System.out.println(Math.floor(6.6));

System.out.println(Math.floorDiv(-6, 4));

System.out.println(Math.floorMod(6, 4));
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/490450.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号