• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
漫椿
博客园    首页    新随笔    联系   管理    订阅  订阅
Math类

Math类

1.Math类,这个类包含用于执行基本数学运算的方法

//圆周率

System.out.println(Math.PI);

//绝对值

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

//天花板 向上去整

 

System.out.println(Math.ceil(12.4));

//地板 向下取整

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

//获取最大值

System.out.println(Math.max(12, 55));

//获取最小值

System.out.println(Math.min(12, 1));

//获取n的次方

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

//随机生成

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

//四舍五入

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

//开平方

System.out.println(Math.sqrt(16))。

 
posted on 2020-06-04 11:35  编程耽误的厨子  阅读(109)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3