zoukankan      html  css  js  c++  java
  • 数字与字符串系列教材 (三)- Java Math类常用方法

    java.lang.Math提供了一些常用的数学运算方法,并且都是以静态方法的形式存在

    步骤1:四舍五入, 随机数,开方,次方,π,自然常数
    步骤2:练习-数学方法
    步骤3:答案-数学方法
    步骤4:练习-质数
    步骤5:答案-质数

    步骤 1 : 四舍五入, 随机数,开方,次方,π,自然常数

    package digit;

      

    public class TestNumber {

      

        public static void main(String[] args) {

            float f1 = 5.4f;

            float f2 = 5.5f;

            //5.4四舍五入即5

            System.out.println(Math.round(f1));

            //5.5四舍五入即6

            System.out.println(Math.round(f2));

             

            //得到一个0-1之间的随机浮点数(取不到1)

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

             

            //得到一个0-10之间的随机整数 (取不到10)

            System.out.println((int)( Math.random()*10));

            //开方

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

            //次方(2的4次方)

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

             

            //π

            System.out.println(Math.PI);

             

            //自然常数

            System.out.println(Math.E);

        }

    }


    更多内容,点击了解: https://how2j.cn/k/number-string/number-string-math/319.html

  • 相关阅读:
    Win32 键盘事件
    好用的Markdown 编辑器及工具
    如何激发您孩子的学习动力和兴趣
    横扫芯片后,紫光欲进军公有云 数百亿资金已到位(大事表)
    C#更改控制台文本颜色
    I/O多路复用
    Python 安装 httpie
    Elasticsearch 5.0
    认证架构
    注册微信小程序
  • 原文地址:https://www.cnblogs.com/Lanht/p/12615529.html
Copyright © 2011-2022 走看看