- 1、本文档共25页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Java JDK 6学习笔记——ppt简体版 第05章
* * * * * * * * * * * * * * * * * * * 第5章 阵 列 一维数组、二维数组 进阶数组观念 一维数组对象 宣告一个数组并初始数组内容 指定的索引值不可超出数组范围 会发生ArrayIndexOutOfBoundsException length为数组对象的属性成员 int[] score = {90, 85, 55, 94, 77}; for(int i = 0; i score.length; i++) System.out.printf(score[%d] = %d\n, i, score[i]); 一维数组对象 当您宣告一个数组时,其实就是在配置一个数组对象 一个完整的数组宣告方式如下 int[] arr = new int[10]; 一维数组对象 数据型态 初始值 byte 0 short 0 int 0 long 0L float 0.0f double 0.0d char \u0000 boolean false 一维数组对象 int[] arr = new int[10]; System.out.print(arr初始值: ); for(int i = 0; i arr.length; i++) { System.out.print(arr[i] + ); arr[i] = i; } System.out.print(\narr设定值: ); for(int i = 0; i arr.length; i++) System.out.print(arr[i] + ); System.out.println(); 一维数组对象 在使用new新增数组时一并指定初始值 int[] score = new int[] {90, 85, 55, 94, 77}; for(int i = 0; i score.length; i++) System.out.printf(score[%d] = %d\n, i, score[i]); 一维数组对象 int length = scanner.nextInt(); float[] score = new float[length]; //动态配置长度 for(int i = 0; i score.length; i++) { System.out.print(输入分数:); float input = scanner.nextFloat(); score[i] = input; } 可以使用动态的方式来宣告数组长度,而不用在程序中事先决定数组大小 二维数组对象 二维数组使用「名称」与「两个索引」来指定存取数组中的元素 以对象的方式来配置一个二维数组对象 int[][] arr = {{1, 2, 3}, {4, 5, 6}}; for(int i = 0; i arr.length; i++) { for(int j = 0; j arr[0].length; j++) System.out.print(arr[i][j] + ); System.out.println(); } int[][] arr = new int[2][3]; 二维数组对象 以对象的方式来配置一个二维数组对象 int[][] arr = new int[2][3]; 二维数组对象 int[][] arr = {{1, 2, 3}, {4, 5, 6}}; int[] foo = arr[0]; //将arr[0]所参考的数组对象指定给foo for(int i = 0; i foo.length; i++) { System.out.print(foo[i] + ); } System.out.println(); foo = arr[1]
您可能关注的文档
- Exchange 2007 配置和启用POP.和Imap服务.docx
- Exchange 2007 配置和启用POP和Imap服务.docx
- explicit 关键字.doc
- Eyekloc英语四级考试历年常考高频词汇(体验英语unit 1 to unit 4)文库.doc
- ext课件大体介绍.ppt
- F-35 EOTS Targeting System Successfully Completes Inaugural Flight Test.doc
- F5交换机配置.doc
- fannyi.doc
- FANUC机器人培训.doc
- File System Layout Implementation.ppt
文档评论(0)