JavaSE——System类、Math类、BigInteger与BigDecimal

目录

一、System类

          1.概述

          2.成员变量                

          3.成员方法

二、Math类

         1.概述

         2.常用方法

三、BigInteger与BigDecimal

       ⒈BigInteger

           ⑴概述

          ⑵常用方法              

      ⒉BigDecimal

         ⑴概述

         (2)常用方法


一、System类

          1.概述

                  System类代表系统,系统级的很多属性和控制方法都放置在该类的内部。该类位于java.lang包。

                  由于该类的构造器都是private的,所以无法创建该类的对象,也就是无法实例化该类。其内部的成员变量和成员方法都是static的,所以也可以很方便的进行调用。

          2.成员变量                

public final static InputStream in = null;        //标准输入流(键盘输入)
public final static PrintStream out = null;       //标准输出流(显示器)
public final static PrintStream err = null;       //标准错误输出流(显示器)

          3.成员方法

//1.该方法的作用是返回当前的计算机时间,时间表达格式为当前的计算机时间与GMT时间(格林威治时间)
//  1970年1月1号0时0分0秒所差的毫秒数
static native long currentTimeMills();    

//2.该方法的作用是退出程序。其中status的值为0代表正常退出,非零代表异常退出。使用该方法可以在图形
//  界面编程中实现程序的退出功能等。
static void exit(int status);

//3.该方法的作用是请求系统进行垃圾回收。至于系统是否立即回收,则取决于系统中垃圾回收算法的实现以及
//  系统执行时的情况。
static void gc();

//4.该方法的作用是获得系统中属性名为key的属性对应的值。系统中常见的属性名以及属性的作用如下图
static String getProperty(String key);

    public void test01(){
        System.out.println(System.getProperty("java.version")); //JDK的版本:1.8.0_77
        System.out.println(System.getProperty("java.home"));    //Java的安装目录:C:\Program Files\Java\jdk1.8.0_77\jre
        System.out.println(System.getProperty("os.name"));      //操作系统的名称:Windows 7
        System.out.println(System.getProperty("os.version"));   //操作系统的版本:6.1
        System.out.println(System.getProperty("user.name"));    //当前操作系统用户的账户名称:Administrator
        System.out.println(System.getProperty("user.home"));    //当前操作系统用户的主目录:C:\Users\Administrator
        System.out.println(System.getProperty("user.dir"));     //用户的当前工作目录:F:\JavaSenior\Day01
    }

二、Math类

         1.概述

                 java.lang.Math提供了一系列的静态方法用于科学计算。其方法的参数和返回值类型一般为double类型。

         2.常用方法

abs 绝对值
acos,asin,atan,cos,sin,tan 三角函数
sqrt 平方根
pow(double a,doble b) a的b次幂
log 自然对数
exp e为底指数
max(double a,double b)
min(double a,double b)
random() 返回0.0到1.0的随机数
long round(double a) double型数据a转换为long型(四舍五入)
toDegrees(double angrad) 弧度—>角度
toRadians(double angdeg) 角度—>弧度

三、BigInteger与BigDecimal

       ⒈BigInteger

           ⑴概述

                     Integer类作为int的包装类,能存储的最大整型值为2^31-1,Long类也是有限的,最大为2^63-1。如果要表示再大的整数,不管是基本数据类型还是他们的包装类都无能为力,更不用说进行运算

                     java.math包的BigInteger可以表示不可变的任意精度的整数。BigInteger 提供所有 Java 的基本整数操作符的对应物,并提供 java.lang.Math 的所有相关方法。另外,BigInteger 还提供以下运算:模算术、GCD 计算、质数测试、素数生成、位操作以及一些其他操作

          ⑵常用方法              

public BigInteger abs()://返回此 BigInteger 的绝对值的 BigInteger。
BigInteger add(BigInteger val) ://返回其值为 (this + val) 的 BigInteger
BigInteger subtract(BigInteger val) ://返回其值为 (this - val) 的 BigInteger
BigInteger multiply(BigInteger val) ://返回其值为 (this * val) 的 BigInteger
BigInteger divide(BigInteger val) ://返回其值为 (this / val) 的 BigInteger。整数相除只保留整数部分。
BigInteger remainder(BigInteger val) ://返回其值为 (this % val) 的 BigInteger。
BigInteger[] divideAndRemainder(BigInteger val)://返回包含 (this / val) 后跟(this % val) 的两个 BigInteger 的数组。
BigInteger pow(int exponent) ://返回其值为 (thisexponent) 的 BigInteger。

      ⒉BigDecimal

         ⑴概述

                  一般的Float类和Double类可以用来做科学计算或工程计算,但在商业计算中要求数字精度比较高,故用到java.math.BigDecimal类。

                   BigDecimal类支持不可变的、任意精度的有符号十进制定点数

         (2)常用方法

public BigDecimal add(BigDecimal augend)
public BigDecimal subtract(BigDecimal subtrahend)
public BigDecimal multiply(BigDecimal multiplicand)
public BigDecimal divide(BigDecimal divisor, int scale, int roundingMod)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值