一维数组和二维数组

来源:互联网 发布:淘宝内部优惠券可信吗 编辑:程序博客网 时间:2024/04/30 19:25

一堆数组

数组
int 的默认值是0
Sting的默认值是null
boolean的默认类型是false
数组一担初始化他的长度是不可改变的


数组的四步走:
1.声明数组
2.分配数组
3.赋值
4.处理数据




数组的格式
int[ ] scores = new int[2];

scores[0] = 90;

scores[1] = 85;

System.out.println(scores[0]);

}
}

数组的格式 动态
int[ ] scores = new int[5];
//声明
scores[0] = 90;

scores[1] = 85;

System.out.println(scores[5]);
//结果为0  int数组默认类型为0
}


第二种格式  静态
int[] scores = new int[]{90,85,70,65,55}
System.out.println(scores[4]);//输入结果55
}


二维数组  静态
int arr[][]={{1,2},{3},{7,8,56}}
二维数组  动态
int a[][]=new int[3][];
a[0]=new int[2];
a[1]=new int[4];
a[2]=new int[3];