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

Math类 Random类 System类

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

Math类 Random类 System类

Math 类 ● java.lang.Math 提供了一系列静态方法用于科学计算;其方法的参数和 返回值类型一般为 double 型。 abs 绝对值 sqrt 平方根 pow(double a, double b) a 的 b 次幂 max(double a, double b) min(double a, double b) random() 返回 0.0 到 1.0 的随机数 long round(double a) double 型的数据 a 转换为 long 型(四舍五入)
public class MathDemo {

    public static void main(String[] args) {
           
        System.out.println(Math.PI);
        System.out.println(Math.abs(-1));
        System.out.println(Math.sqrt(9));
        System.out.println(Math.random());//返回0-1之间随机数

        System.out.println(Math.floor(9.9));//向下取整
        System.out.println(Math.ceil(9.1));//向上取整
        System.out.println(Math.round(9.6));//四舍五入


    }
}
Random 类 ● Random类概述 此类用于产生随机数 ● 构造方法 public Random()   成员方法 public int nextInt() public int nextInt(int n)
public class RandomDemo {

    public static void main(String[] args) {
        Random r = new Random();
        //System.out.println(r.nextInt());//在int的范围内随机取出
        //System.out.println(r.nextInt(4));//0--<4  在指定的区间内随机取出

        //System.out.println(r.nextBoolean());

        byte[] b = new byte[5];//随机取出 数组.length个随机数
              r.nextBytes(b);
        System.out.println(Arrays.toString(b));


    }
}
System 类 ● System 类概述 System 类包含一些有用的类字段和方法。它不能被实例化。 ● 成员方法 public static void exit(int status) public static long currentTimeMillis()
public class SystemDemo {
 

    public static void main(String[] args) {
        //public final static PrintStream out = null;
        // System.out.print(1);

        

        //1637483235781 是自1970.1.1 0:0:0 --- 程序运行时的那一刻的时间差(毫秒为单位)
        //Long s =  System.currentTimeMillis();
        //System.out.println(s);

        //System.exit(0); 退出虚拟机

       //System.gc(); 垃圾回收 一般程序中不使用

        //System.out.println("qqqqqqqqqqq");

        //arraycopy(Object src, int srcPos, Object dest, int destPos, int length)
         int a[] = {1,2,3,4,5};
         int b[] = new int[10];

         
         System.arraycopy(a,1,b,0,4); //系统中提供的最底层的数组内容复制方法
         System.out.println(Arrays.toString(b));

    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/992616.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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