zoukankan      html  css  js  c++  java
  • System类+Math类+Arrays类

    System类

    System中代表程序所在系统,提供了对应的一些系统属性信息,和系统操作

    currentTimeMillis()   获取当前系统时间与1970年01月01日00:00点之间的毫秒差值

    exit(int status) 用来结束正在运行的Java程序。参数传入一个数字即可。通常传入0记为正常状态,其他为异常状态

    gc() 用来运行JVM中的垃圾回收器,完成内存中垃圾的清除。

    getProperty(String key) 用来获取指定(字符串名称)中所记录的系统属性信息

    Math类

    Math 类是包含用于执行基本数学运算的方法的数学工具类

    l  abs方法,结果都为正数

    double d1 = Math.abs(-5); // d1的值为5

    double d2 = Math.abs(5); // d2的值为5

    l  ceil方法,结果为比参数值大的最小整数的double值

    double d1 = Math.ceil(3.3); //d1的值为 4.0

    double d2 = Math.ceil(-3.3); //d2的值为 -3.0

    double d3 = Math.ceil(5.1); // d3的值为 6.0

    l  floor方法,结果为比参数值小的最大整数的double值

    double d1 = Math.floor(3.3); //d1的值为3.0

    double d2 = Math.floor(-3.3); //d2的值为-4.0

    double d3 = Math.floor(5.1); //d3的值为 5.0

    l  max方法,返回两个参数值中较大的值

    double d1 = Math.max(3.3, 5.5); //d1的值为5.5

    double d2 = Math.max(-3.3, -5.5); //d2的值为-3.3

    l  min方法,返回两个参数值中较小的值

    double d1 = Math.min(3.3, 5.5); //d1的值为3.3

    double d2 = Math.max(-3.3, -5.5); //d2的值为-5.5

    l  pow方法,返回第一个参数的第二个参数次幂的值

    double d1 = Math.pow(2.0, 3.0); //d1的值为 8.0

    double d2 = Math.pow(3.0, 3.0); //d2的值为27.0

    l  round方法,返回参数值四舍五入的结果

    double d1 = Math.round(5.5); //d1的值为6.0

    double d2 = Math.round(5.4); //d2的值为5.0

    l  random方法,产生一个大于等于0.0且小于1.0的double小数

    double d1 = Math.random();

    Arrays类

    此类包含用来操作数组(比如排序和搜索)的各种方法。需要注意,如果指定数组引用为 null,则访问此类中的方法都会抛出空指针异常NullPointerException

    l  sort方法,用来对指定数组中的元素进行排序(元素值从小到大进行排序)

    //源arr数组元素{1,5,9,3,7}, 进行排序后arr数组元素为{1,3,5,7,9}

    int[] arr = {1,5,9,3,7};

    Arrays.sort( arr );

    l  toString方法,用来返回指定数组元素内容的字符串形式

    int[] arr = {1,5,9,3,7};

    String str = Arrays.toString(arr); // str的值为[1, 3, 5, 7, 9]

    l  binarySearch方法,在指定数组中,查找给定元素值出现的位置。若没有查询到,返回位置为-(这个值应该在的位置)-1。要求该数组必须是个有序的数组。

    int[] arr = {1,3,4,5,6};

    int index = Arrays.binarySearch(arr, 4); //index的值为2

    int index2= Arrasy.binarySearch(arr, 2); //index2的值为-2

  • 相关阅读:
    Linux的find命令
    Shell环境变量文件
    Spring事务配置的五种方式 巨全!不看后悔,一看必懂!
    高性能C++网络库libtnet实现:Connection
    log4j的一些配置
    MySQL的表分区
    MySQL中的datetime与timestamp比较
    如何成为一名优秀的web前端工程师
    双机热备份
    MySQL错误“Specified key was too long; max key length is 1000 bytes”的解决办法
  • 原文地址:https://www.cnblogs.com/sy130908/p/11458684.html
Copyright © 2011-2022 走看看