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

  • 相关阅读:
    力拓题目 5-8-575,657,707,771
    力拓题目1-4-7,217,344,557
    解码,编码,文件的基本操作
    集合类型内置方法和拷贝浅拷贝深拷贝
    列表元祖字典内置方法
    数字类型内置方法
    字符串类型内置方法
    hdu2262 高斯消元
    hdu1757 构造矩阵
    poj1222 高斯消元
  • 原文地址:https://www.cnblogs.com/Lanht/p/12615529.html
Copyright © 2011-2022 走看看