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);
广告