黑马程序员技术交流社区
标题:
数组笔记01
[打印本页]
作者:
桑葚之甜
时间:
2015-9-26 19:19
标题:
数组笔记01
一.同一种类型数据的集合。其实,数组就是一个容器。
格式1:
元素类型 [] 数组名 = new 元素类型[元素个数或数组长度];
eg:
int[] arr = new int[5];
格式2:
元素类型[] 数组名 = new 元素类型[]{元素,元素,...};
二.注:用到数组时就要立马考虑到遍历数组。
1.遍历并打印数组元素
class ArrayBianLi {
//遍历数组
public static void main(String[] args) {
int arr[] ={2,34,24,1,4,5};
Demo.Print();//调用Demo这个类里Print()的方法。
//格式:类.函数名();
for (int x=0;x<arr.length ;x++ )
{
System.out.println(arr[x]);
}
}
}
class Demo {
public static void Print() {
System.out.println("哇哦");
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2