一维数组二维数组的动态,静态赋值写法

一维数组的动态和静态写法

/**
	 * 一维数组的几种写法	
	 */
	// 1 动态输入
		int[] arr = new int[5];
		arr[0] = 75 ;
		arr[1] = 65 ;
		arr[2] = 71 ;
		arr[3] = 55 ;
		arr[4] = 95 ;
	// 2 静态输入	
		int[] str = new int[] {0,5,9,6,8,1,7,3};
		
	// 3 静态输入
		int[] sort = {1,5,9,6,8,7,3,2};

二维数组的动态和静态写法

	/**
		 * 二维数组的几种写法	
		 * 二维数组相当于大数组中,带有多个小数组,小数组的长度不固定,看情况自己需要写入
		 */
		int[][] score = new int[3][];
	/* 第一种 动态输入	
		score[0] = new int[3] ;
		score[1] = new int[3] ;
		score[2] = new int[3] ;
		score[0][0] = 1 ;
		score[0][1] = 99 ;
		score[0][2] = 89 ;
		score[1][0] = 2 ;
		score[1][1] = 89 ;
		score[1][2] = 98 ;
		score[2][0] = 3 ;
		score[2][1] = 78 ;
		score[2][2] = 68 ;
	*/
	// 第二种动态输入
		score[0] =	new int[] {1,78,89} ;
		score[1] = new int[] {2,96,59};
		score[2] = new int[] {3,79,99};
	
		
	//静态输入,不写长度,直接写入,二维
		int[][] arr = new int [][] {{1,2,3},{9,5,6,7},{8,1,4}} ;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值