1 / 12

第7章 Java 数组

第7章 Java 数组. 面向对象的程序设计与 JAVA 娄不夜 王利 编著 主讲:胡传福 E-mail:hucf@dgut.edu.cn. 数组. 一个数组包含一组变量,叫数组元素 元素的数目称为数组的长度 数组元素通过数组变量名和一个下标来标识 数组元素都必须有相同的数据类型. 数组类型. 数组类型(即数组对象的类型)用数组元素的类型跟一对方括号来表示;数组中的每个元素都象一个简单变量 int [] char [] String[] Point[] Object[]. 数组变量. 数组通过变量来引用和操纵.需要 声明、创建 。

zoe
Télécharger la présentation

第7章 Java 数组

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第7章 Java 数组 面向对象的程序设计与JAVA 娄不夜 王利 编著 主讲:胡传福 E-mail:hucf@dgut.edu.cn Chapter 7

  2. 数组 • 一个数组包含一组变量,叫数组元素 • 元素的数目称为数组的长度 • 数组元素通过数组变量名和一个下标来标识 • 数组元素都必须有相同的数据类型 Chapter 7

  3. 数组类型 数组类型(即数组对象的类型)用数组元素的类型跟一对方括号来表示;数组中的每个元素都象一个简单变量 int[] char[] String[] Point[] Object[] Chapter 7

  4. 数组变量 • 数组通过变量来引用和操纵.需要声明、创建。 int[]ai;  int ai[]; char[]ac; String[]as; Point[]ap; Object[]ao; Chapter 7

  5. 数组创建 • 数组变量定义语句只是声明某个变量的类型是某种数组类型,并没有创建具体的数组对象。 • 创建格式:new <类型>[<表达式>] • 表达式的值必需是非负整数 • 创建举例: • ai=newint[10]; • ap=newPoint[4*12/6+3]; • 声明与创建合在一起:int[]ai=newint[10]; Chapter 7

  6. 数组元素的默认初值 Chapter 7

  7. 数组初始化块 • 格式: • <类型>[]<数组变量>={<表达式表>}; • 例子: • int[]ai={2,3,6,8,12,14,16}; • Point[]ap={newPoint(),newPoint(5,10),newPoint(12,7)}; Chapter 7

  8. 数组元素类型为基本型 Chapter 7

  9. 数组元素类型为引用型 Chapter 7

  10. 数组访问 • 格式:<数组对象引用>[<下标>] Chapter 7

  11. 二维数组 • 类型:int[][] • 声明与创建:int[][] aai= newint[3][4]; Chapter 7

  12. 二维数组示意图 Chapter 7

More Related