Day02 数组

来源:互联网 发布:mac工行网银控件 编辑:程序博客网 时间:2024/04/29 03:14

声明数组:
数据类型[] 数组名:

int[] scores;

数组类型 数组名[];

double height[];

分配空间:

scores = new int[5];double = new double[5];

赋值:

scores[0]=1;scores[1]=2;

直接定义数组:

int[] scores={1,2,3,4};int[] scores= new int[]{1,2,3,4}

数组中常用的方法
Arrays.sort(数组name) 排序
Arrays.toString(数组name) 数组转化为字符串

遍历数组
for()循环
foreach 遍历 for( 数组类型 数组中的值:数组)

java中的方法
Ø 无参无返回值方法
Ø 无参带返回值方法
Ø 带参无返回值方法
Ø 带参带返回值方法
方法重载 :同名不同参

0 0
原创粉丝点击