类型转换拓展
package com.company;
public class Demo5 {
? ? public static void main(String[] args) {
? ? ? ? System.out.println("類型轉換===========================");
? ? ? ? System.out.println("byte 1字節=>short 2,char 2=》int 4==>long 8==>float 4==>double 8=================小數高于整數的");
? ? ? ? int i=128;
? ? ? ? byte b=(byte)i;//內存溢出
? ? ? ? double b1=i;
? ? ? ? //Byte右鍵看源碼 ?byte -128~127
? ? ? ? System.out.println(i);
? ? ? ? System.out.println(b);
? ? ? ? System.out.println(b1);
? ? ? ? System.out.println("================注意");
? ? ? ? /*
? ? ? ? * 注意點:
? ? ? ? * 1.不能對boolean轉換
? ? ? ? * 2.不能把對象類型轉換為不相干的類型
? ? ? ? * 3.大變小,強制轉換
? ? ? ? * 4.轉換的時候可能存在內存溢出,或者精度問題!
? ? ? ? * */
? ? ? ? int i1=128;
? ? ? ? //boolean b111=i; Error:(20, 22) java: 不兼容的類型: int無法轉換為boolean
? ? ? ? System.out.println("===========(int)=============");
? ? ? ? System.out.println((int)23.7);
? ? ? ? System.out.println((int)-45.89f);
? ? }
}
類型轉換===========================
byte 1字節=>short 2,char 2=》int 4==>long 8==>float 4==>double 8=================小數高于整數的
128
-128
128.0
================注意
===========(int)=============
23
-45
char=================
98
b
加qq群422464063學習
總結
- 上一篇: Python Chainmap函数 -
- 下一篇: jq之slideup()