?? typeconversion.java
字號:
//TypeConversion.java
//Java中的類型轉換
public class TypeConversion
{
public static void main(String args[ ])
{
char a=1;
byte b=2;
short c=3;
int d=4;
byte e;
e=(byte)(a+b+c+d); //將"a+b+c+d"的值強制轉化為byte型
//如果寫成“e=a+b+c+d;”,將出錯
short f;
f=(short)(a+b+c+d); //將"a+b+c+d"的值強制轉化為byte型
//如果寫成“f=a+b+c+d;”,將出錯
int g;
g=a+b+c+d; //a,b,c,d自動轉換為int型再計算
float h;
h=a+b+c+d; //a,b,c,d自動轉換為float型再計算
double i;
i=a+b+c+d; //a,b,c,d自動轉換為double型再計算
System.out.println("e="+e);
System.out.println("f="+f);
System.out.println("g="+g);
System.out.println("h="+h);
System.out.println("i="+h);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -