Wednesday, August 04, 2010

Java基本資料範圍


public class DataRange {
public static void main(String[] args) {
System.out.println("byte range: " + Byte.MAX_VALUE + " ~ " + Byte.MIN_VALUE);
System.out.println("short range: " + Short.MAX_VALUE + " ~ " + Short.MIN_VALUE);
System.out.println("int range: " + Integer.MAX_VALUE + " ~ " + Integer.MIN_VALUE);
System.out.println("long range: " + Long.MAX_VALUE + " ~ " + Long.MIN_VALUE);
System.out.println("float range: " + Float.MAX_VALUE + " ~ " + Float.MIN_VALUE);
System.out.println("double range: " + Double.MAX_VALUE + " ~ " + Double.MIN_VALUE);
}
}



C:\Java\exam>javac DataRange.java

C:\Java\exam>java DataRange
byte range: 127 ~ -128
short range: 32767 ~ -32768
int range: 2147483647 ~ -2147483648
long range: 9223372036854775807 ~ -9223372036854
float range: 3.4028235E38 ~ 1.4E-45
double range: 1.7976931348623157E308 ~ 4.9E-324


byte使用8位元; short使用16位元; int使用32位元; long使用64位元
float使用32位元; double使用64位元
char使用16位元;

左邊的部分都可以指定(assignment)給右邊的型別:
byte --> short --> int --> long --> float --> double

No comments:

Post a Comment