型態類型 | 宣告類型 | 位元數 | 範圍 |
整數 | byte | 8 | -128 ~ 127 |
short | 16 | -32768 ~ 32767 | |
int | 32 | -2147483648 ~ 2147483647 | |
long | 64 | -9223372036854775808 ~ 9223372036854775807 | |
浮點數 | float | 32 |
負值:-3.402823E38~-1.401298E-45 正值:1.401298E-45~3.402823E38 |
double | 64 |
負值:-1.797693134E3.8~4.9406564584124E-324 正值:4.94.6564584E-324~1.797693134862E308 |
|
布林值 | boolean | 1 | true, false |
字元 | char | 16 | '\u0000' - '\uffff' |
程式 | 輸出 |
public class test{ int x = 1; public static void main(String[] args){ System.out.println("x is " + x); x = 5; abc(); } void abc(){ System.out.println("x is " + x); } } | x is 1 x is 5 |
程式 | 輸出 |
public class test{ public static void main(String[] args){ int x = 1; abc(); } void abc(){ System.out.println("x is " + x); } } | Error |