Java中原始数据类型的默认值
基本数据类型由该语言预先定义,并由Java中的关键字命名。这是显示原始数据类型的默认值的示例。
示例
public class Demo { static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; public static void main(String[] args) { System.out.println("Default values....."); System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); System.out.println("Val5 = " + val5); System.out.println("Val6 = " + val6); } }
输出结果
Default values..... Val1 = false Val2 = 0.0 Val3 = 0.0 Val4 = 0 Val5 = 0 Val6 = null
上面,我们首先声明了特定类型的变量。请记住,要获取默认值,您无需为变量分配值。
static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6;
现在要显示默认值,您只需要打印变量。
System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); System.out.println("Val5 = " + val5); System.out.println("Val6 = " + val6);