数组的默认值

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]);

}
}

}

转载于:https://www.cnblogs.com/kaikai97/p/11211468.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值