Java 语言提供了八种基本类型。六种数值类型(四种整数、两种浮点)、一种字符类型和一种布尔值。
public class DataType {
static byte b;
static short s;
static int i;
static long l;
static float f;
static double d;
static char c;
static boolean bool;
public static void main(String args[]) {
System.out.println("byte[Size:"+Byte.SIZE
+", Default value:"+b
+"; Data range:"+Byte.MIN_VALUE+" ~ "+Byte.MAX_VALUE+"]");
System.out.println("short[Size:"+Short.SIZE
+", Default value:"+s
+"; Data range:"+Short.MIN_VALUE+" ~ "+Short.MAX_VALUE+"]");
System.out.println("int[Size:"+Integer.SIZE
+", Default value:"+i
+"; Data range:"+Integer.MIN_VALUE+" ~ "+Integer.MAX_VALUE+"]");
System.out.println("long[Size:"+Long.SIZE
+", Default value:"+l
+"; Data range:"+Long.MIN_VALUE+" ~ "+Long.MAX_VALUE+"]");
System.out.println("float[Size:"+Float.SIZE
+", Default value:"+f
+"; Data range:"+Float.MIN_VALUE+" ~ "+Float.MAX_VALUE+"]");
System.out.println("double[Size:"+Double.SIZE
+", Default value:"+d
+"; Data range:"+Double.MIN_VALUE+" ~ "+Double.MAX_VALUE+"]");
System.out.println("char[Size:"+Character.SIZE
+", Default value:"+c
+"; Data range:"+(int)Character.MIN_VALUE+" ~ "+(int)Character.MAX_VALUE+"]");
System.out.println("boolean[Default value:"+bool
+"; Data range:"+Boolean.TRUE+" & "+Boolean.FALSE+"]");
}
}
运行结果:
你适合学Java吗?4大专业测评方法
代码逻辑 吸收能力 技术学习能力 综合素质
先测评确定适合在学习