Java程序设计中文07slide概要1.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java程序设计中文07slide概要1

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 Chapter 7 多维数组 Objectives To give examples of representing data using two-dimensional arrays (§7.1). To declare variables for two-dimensional arrays, create arrays, and access array elements in a two-dimensional array using row and column indexes (§7.2). To program common operations for two-dimensional arrays (displaying arrays, summing all elements, finding min and max elements, and random shuffling) (§7.3). To pass two-dimensional arrays to methods (§7.4). To write a program for grading multiple-choice questions using two-dimensional arrays (§7.5). To solve the closest-pair problem using two-dimensional arrays (§7.6). To check a Sudoku solution using two-dimensional arrays (§7.7). To use multidimensional arrays (§7.8). 引言   上章介绍过一维数组如何存储线性的元素集合。可以使用二维数组存储矩阵或表格。例如,使用二维数组就可以存储下面这个描述城市之间距离的表格。 声明和创建二维数组 // Declare array ref var dataType[][] refVar; // Create array and assign its reference to variable refVar = new dataType[10][10]; // Combine declaration and creation in one statement dataType[][] refVar = new dataType[10][10]; // Alternative syntax dataType refVar[][] = new dataType[10][10]; 声明二维数组变量并创建二维数组 int[][] matrix = new int[10][10]; or int matrix[][] = new int[10][10]; matrix[0][0] = 3; for (int i = 0; i matrix.length; i++) for (int j = 0; j matrix[i].length; j++) matrix[i][j] = (int)(Math.random() * 1000); double[][] x; Two-dimensional Array Illustration Declaring, Creating, and Initializing Using Shorthand Notations 也可以使用数组初始化来声明、创建和初始化一个二维数组。例如: 二维数组的长度 int[][] x = new int[3][4]; 二维数组的长度 int[][] array = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12} }; 锯齿数组 二维数组中的每一行本身就是一个数组,因些,各行的长度就可以不同,这样的数组称之为锯齿数组。 int[][] matrix = { {1, 2, 3, 4, 5}, {2, 3, 4, 5}, {3, 4, 5}, {4, 5}, {5} }; 锯齿数组 处理二维数组 See the examples in the text. (Initializing arrays with input values) (Printing arrays) (Summing all ele

文档评论(0)

yaocen + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档