《疯狂Java讲义精粹》读书笔记1 数据类型特殊数据

 1 //
 2 /**
 3 * 1.Java提供3个特殊的浮点数值
 4 *   1).正无穷大:POSITIVE_INFINITY
 5 *   2).负无穷大:NEGATIVE_INFINITY
 6 *   3).非数:NaN
 7 * 2.所有的正无穷大数和负无穷大数都是相等的,
 8 *   所有的非数都是不相等的,甚至NaN和NaN
 9 * 3.只有浮点数除以0才会得到正无穷大或负无穷大
10 *   如果一个整数除以0会抛出:ArithmeticException:/by zero
11 * 4.Java 7 新增二进制整数,还可以在数值中使用下划线分隔
12 */
13 
14 public class 特殊数据{
15     public static void main(String []args){
16         float af = 5.234556291f;
17         System.out.println("af = " + af);//输出会发生改变
18 
19         double a = 0.0;
20         double c = Double.NEGATIVE_INFINITY;
21         float d = Float.NEGATIVE_INFINITY;
22 
23         //float和double的负无穷是相等的
24         System.out.println(c == d);
25 
26         //将出现非数
27         System.out.println("无穷大 - 无穷大 = " + (c - d));
28 
29         //0.0除以0.0将输出非数
30         System.out.println(a / a);
31 
32         //两个非数之间是不相等的
33         System.out.println(a / a == Float.NaN);
34 
35         //得到 -Infinity
36         System.out.println(-6 / a);
37 
38         //抛出除0异常
39         //System.out.println(6/0);
40 
41         //Java7新增的数据类型
42         int binInt = 0b1101_0101;
43         System.out.println("bi = " + binInt);
44 
45         //System.out.println("5 % 0 = " + 5%0);//异常
46         
47         //得到非数
48         System.out.println("5.0 % 0 = " + (5.0 % 0.0));
49 
50         //得到0.0
51         System.out.println("0 % 5.0 = " + (0%5.0));
52 
53         System.out.println(-5 >> 2);
54         System.out.println(-5 >>> 2);
55 
56         System.out.println("5 == 5.0: " + (5 == 5.0));
57     }
58 }

原文地址:https://www.cnblogs.com/CocoonFan/p/2937622.html