Java数据类型
JAVA语言中定义了8种基本的数据类型,来保存变量。与它的前辈C和C++语言一样,JAVA要求程序中的每一个变量都规定自己的类型。正因为如此,JAVA属于强类型语言,从而不同于JavaScript这样的弱类型脚本语言。下面我们来看看这8种类型:
public class FloatDouble
{
public static void main(String[] args)
{
System.out.println("byte:" + Byte.SIZE + " bit. (" + Byte.MIN_VALUE + " ~ " + Byte.MAX_VALUE + ")");
System.out.println("short:" + Short.SIZE + " bit. (" + Short.MIN_VALUE + " ~ " + Short.MAX_VALUE + ")");
System.out.println("int:" + Integer.SIZE + " bit. (" + Integer.MIN_VALUE + " ~ " + Integer.MAX_VALUE + ")");
System.out.println("long:" + Long.SIZE + " bit. (" + Long.MIN_VALUE + " ~ " + Long.MAX_VALUE + ")");
System.out.println("float:" + Float.SIZE + " bit. (" + Float.MIN_VALUE + " ~ " + Float.MAX_VALUE + ")");
System.out.println("double:" + Double.SIZE + " bit. (" + Double.MIN_VALUE + " ~ " + Double.MAX_VALUE + ")");
System.out.println("boolean:" + " (" + Boolean.TRUE + " / " + Boolean.FALSE + ")");
System.out.println("char:");
}
}
//输出
byte:8 bit. (-128 ~ 127)
short:16 bit. (-32768 ~ 32767)
int:32 bit. (-2147483648 ~ 2147483647)
long:64 bit. (-9223372036854775808 ~ 9223372036854775807)
float:32 bit. (1.4E-45 ~ 3.4028235E38)
double:64 bit. (4.9E-324 ~ 1.7976931348623157E308)
boolean: (true / false)
char:16位,存储Unicode码,用单引号赋值。
整形变量:byte, short, int , long ,
浮点型变量:float , double
布尔字符型:boolean , char