数组的默认值


package com.kk.java;

public class TestArray1 {
public static void main(String[] args) {

//对于基于基本数据类型的变量创建的数组:byte short int long float double char boolean
//1、对于byte short int long而言:创建数组后,元素默认为0
int[] scores = new int[4];
scores[0] = 77;
scores[3] = 88;
for(int i = 0;i < scores.length;i++) {
System.out.println(scores[i]);

}
//2、对于float double而言:默认值为0.0
float[] f = new float[3];
for(int i = 0;i < f.length;i++) {
System.out.println(f[i]);

}
//3、对于char而言:默认为空格
char[] c = new char[3];
c[2] = 'd';
for(int i = 0;i < c.length;i++) {
System.out.println(c[i]);

}
//4、对于boolean而言:默认为false
//5、对于引用类型的变量构成的数组:默认初始化值为null
String[] strs = new String[4];
strs[0] = "AA";
strs[1] = "BB";
strs[3] = "DD";
for(int i = 0;i < strs.length;i++) {
System.out.println(strs[i]);

}
}

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM