Math类

  1. Math类包含用于执行基本数学运算的方法,如初等数学,对数,平方根和三角函数

  2. 常用方法

    //Math 常用方法(静态方法)
    //1.abs 绝对值
    int abs = Math.abs(-9);
    System.out.println(abs);
    //2.pow 求幂
    double pow = Math.pow(2,4);
    System.out.println(pow); //16.0
    //3.ceil 向上取整,返回>=该参数的最小整数(转成double)
    double ceil = Math.ceil(3.9);
    System.out.println(ceil);//4.0
    //4.floor 向下取整数,返回<=该参数的最大整数(转成double)
    double floor = Math.floor(4.99);
    System.out.println(floor);//4.0
    //5.round 四舍五入 Math.floor(该参数+0.5)
    long round = Math.round(5.51);
    System.out.println(round);//6
    //6.sqrt 求开方
    double sqrt = Math.sqrt(9.0);
    System.out.println(sqrt);//3.0
    //7.random 求随机数
    // random返回的是 0 <= x < 1 之间的一个随机小数
    // a - b 之间的整数:(int)(a + Math.random() * (b - a + 1))
    for (int i = 0; i < 20; i++) {
    System.out.print((int)(2 + Math.random() * (7 - 2 + 1)));
    }
    //8.max , min 返回最大值和最小值
    int min = Math.min(1,9);
    int max = Math.max(45,90);
    System.out.println("min=" + min);
    System.out.println("max=" + max);

最新文章

  1. java面向对象---对象容器
  2. LINUX 6.x 内核升级全过程
  3. MessageBox的常用方法
  4. 面试问题5:const 与 define 宏定义之间的区别
  5. RegExp 对象 (JavaScript)
  6. openldap sshkey & 用户自定义属性
  7. Unix时间戳与C# DateTime时间类型互换
  8. OpenGL-选择与拾取
  9. Android遇到的错误,运行时崩溃
  10. Linux之cuda安装
  11. Educational Codeforces Round 12 E. Beautiful Subarrays 预处理+二叉树优化
  12. Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
  13. Express4 Route笔记
  14. c++ 对象作为参数传递
  15. python网络爬虫学习笔记
  16. Spring 整合 Redis出现的一个Timeout方法找不到的问题
  17. 关于STM32 IAP
  18. Web服务器、应用服务器、Web容器、反向代理服务器区别与联系
  19. hive 学习
  20. leetcode207

热门文章

  1. go语言学习笔记-初识Go语言
  2. Linux操作系统(2):组管理和权限管理
  3. AMS1117降压电路
  4. 【cartogarpher_ros】三: 发布和订阅雷达scan信息
  5. 字符输入流_Reader类&amp;FileReader类介绍和字符输入读取字符数据
  6. JavaWEB-01-MySQL基础
  7. MySQL-过滤数据(WHERE语句)
  8. 5-15 Virtual 虚拟机
  9. 开发中常用的两个JSON方法
  10. Nuget打包并上传教程