java----数组

2020-12-13 04:51

阅读:407

标签:print   str   就是   sys   地址   遍历   静态   system   rgs   

/*
 * 数组:存储同一种数据类型的多个元素的容器
 * 定义格式:
 * A:数据类型[]数组名;(推荐的方式)
 * B:数据类型 数组名[]
 * 举例:
 * int[] arr;
 * int arr[];
 *数组初始化;
 *		A:所谓的数组初始化,就是为数组开辟内存空间,并为数组中的每个元素赋予初始值
 *		B:我们有两种方式可以实现数组的初始化
 *			a:动态初始化    只给出长度,由系统给出初始化值
 *			b:静态初始化    给出初始化值,由系统决定长度
 *动态初始化:
 *		数据类型[] 数组名=new 数据类型[数组长度]
 */
public class ArrayDemo {
	public static void main(String[] args) {
		int[] arr=new int[3];
		System.out.println(arr.toString());//[I@15db9742 输出的是地址值
		System.out.println(arr[0]+" "+arr[1]+" "+arr[2]);// 0 0 0初始化值默认为0
		//数组静态初始化
		int [] arr1={1,2,3,4,5};
		for(int i=0;i

  

java----数组

标签:print   str   就是   sys   地址   遍历   静态   system   rgs   

原文地址:https://www.cnblogs.com/byczyz/p/11123648.html


评论


亲,登录后才可以留言!