天天看点

java数字类

 整数short ,int ,long

浮点数 float double

大整数类biginteger(大整数),bigdecimal(大浮点数),因为整数类和浮点数类所表示的数字都有界限范围,但是大数类没有,可以无穷大

随机数类 random

工具类math

java数字类

 包装类和基本类型的范围是一样的

java数字类
package mooc_8_01;

public class IntegerTest {

  public static void main(String[] args) {
    short a1 = 32767;
    System.out.println(a1);
    //short a2 = 32768;error 越界(最多到32767)
    
    int b1 = 2147483647;
    System.out.println(b1);
    //int b2 = 2147483648; error 越界
    
    long c1 = 1000000000L;//后面要加L
    System.out.println(c1);
    
    long c2 = 2147483647;//隐式做了从int变成long的操作
    System.out.println(c2);
    
    long c3 = 2147483648L;//去掉L将报错;
    System.out.println(c3);
  }

}      
package mooc_8_01;

public class mooc_8_02 {

  public static void main(String[] args) {
    float f1 = 1.23f;
    //float f2 = 1.23;//error ,float赋值必须带f
    double d1 = 4.56d;
    double d2 = 4.56;//double 可以省略末尾的d
    
    System.out.println(f1);
    System.out.println((double)f1);//强制类型转换
    System.out.println(d1);
    System.out.println((float)d2);
    
    System.out.println(f1==1.22999999f);//1.23是等于1.2999999的,表示的不准确
    System.out.println(f1-1.22999999f);
    System.out.println(d2==4.5599999999d);
    System.out.println(d2-4.5599999999d);
  }

}