java学习笔记之 (各种数据类型的数组元素的默认值)

public class TestArray {
public static void main(String[] args)
{
//string类型数组的默认值null
//对于引用类型的属性的默认值是null,如String类型
System.out.println("查看String类型中数组的默认值:");
String[] str=new String[4];
str[0]="aa";
str[1]="bb";
//str[2]="cc";
//str[3]="dd";
for(int i=0;i<4;i++)
{
System.out.println(str[i]);
}
//对于short,int,long,byte而言,创建数组的默认值是0
System.out.println("查看int类型数组的默认值:");
int[] score=new int[4];
score[0]=90;
score[1]=89;
score[2]=34;
for(int i=0;i<score.length;i++)
{
System.out.println(score[i]);
}

System.out.println("查看short类型数组的默认值:");
short[] score1=new short[4];
score1[0]=90;
for(int i=0;i<score1.length;i++)
{
System.out.println(score1[i]);
}

System.out.println("查看long类型数组的默认值:");
long[] score2=new long[4];
score2[0]=90;
for(int i=0;i<score2.length;i++)
{
System.out.println(score2[i]);
}

System.out.println("查看byte类型数组的默认值:");
byte[] score3=new byte[4];
score3[0]=90;
for(int i=0;i<score3.length;i++)
{
System.out.println(score3[i]);
}

//duiyufloat double而言,默认值是0.0
System.out.println("查看float类型数组的默认值:");
float[] score4=new float[4];
score4[0]=23;
for(int i=0;i<score4.length;i++)
{
System.out.println(score4[i]);
}

System.out.println("查看double类型数组的默认值:");
double[] score5=new double[4];
score5[0]=45;
for(int i=0;i<score5.length;i++)
{
System.out.println(score5[i]);
}

//对于char类型
//char类型数组的默认值是空格
System.out.println("查看char类型数组的默认值:");
char[] ch=new char[4];
ch[0]='p';
for(int i=0;i<ch.length;i++)
{
System.out.println(ch[i]);
}
//对于boolean类型的数组默认值
//boolean类型数组的默认值是false
System.out.println("查看boolean数组的默认值:");
boolean[] b=new boolean[4];
b[0]=true;
for(int i=0;i<b.length;i++)
{
System.out.println(b[i]);
}


///引用类型数组的默认值是null
System.out.println("查看引用类型的数组默认值:");
Person[] p=new Person[4];
for(int i=0;i<p.length;i++)
{
System.out.println(p[i]);
}
}
}
class Person
{

}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值