用Eclipse学习数组初次小结

敲代码的时候会出现黄色感叹哈,是一个善意的提醒,如下
The value of the local variable array1 is not used
说明:你创建了一个变量,但是这个变量还没有被调用呢! 此时,在接下来的过程中调用就可以了。

数组是一种引用类型,可以存放同一类型的多种数据,例如基本类型或者引用类型,但是元素类型必须相同。

定义数组
数据类型[ ] 数组名称 ; == 数据类型 数组名称[ ];
定义好数组之后,必须要进行初始化。

初始化:就是在内存当中开辟存放数组的空间,并且给数组赋予一些默认值。
默认值:Int类型默认值为 0,浮点数类型默认值为0.0,布尔默认值为:false,字符默认值为:’ ’ 看起来像一个空格,实际上并不是 \u0000 (Unicod写法),如果是字符串或者是其它引用类型,那么默认值为null (闹,空常量)

初始化:动态初始化、静态初始化
1)、动态初始化:指定数组的长度
动态初始化第一种格式
数据类型[ ] 数组名称 = new 数据类型[数组长度];
动态初始化第二种格式
数据类型[ ] 数组名称;
数组名称 = new 数据类型 [数组长度];
[ ] 表示数组 new表示在内存当中创建空间
左右两侧的数据类型必须都相同。数据名称则是一种自定义的标识符,通过名称可以使用数组当中的数据。
2)、静态初始化:制定数组的内容
a、标准格式:
数据类型[ ] 数组名称 =new 数据类型[ ] {元素1,元素2,元素3,。。。。};
b、简便格式(常用格式)
数据类型 [ ] 数组名称 = {元素内容};
PS:一旦使用了简便格式,那么不可以使用两个步骤的,会报错。

==================================
访问数组当中的具体元素
数组名称[ 下标 ] ;
改变数组当中的具体元素
数组名称 [ 下标 ] = 改变后的元素
将数组当中的某个具体元素赋值给变量

array1 =[1,2,3,4]
int num=array1[2]   println(num); num = 3
double num = array1[2]  println(num); num = 3.0

num的类型,可以是 int和dpuble,int 和double类型可以进行相互转换,但是别的类型进行转换就会报错。
想知道一个数组的长度。
数组名称.length
将会得到一个int类型数字,就是数组的长度。




  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
You are visitor as of October 17, 1996.The Art of Assembly Language ProgrammingForward Why Would Anyone Learn This Stuff?1 What's Wrong With Assembly Language2 What's Right With Assembly Language?3 Organization of This Text and Pedagogical Concerns4 Obtaining Program Source Listings and Other Materials in This TextSection One: Machine OrganizationArt of Assembly Language: Chapter OneChapter One - Data Representation1.0 - Chapter Overview1.1 - Numbering Systems1.1.1 - A Review of the Decimal System1.1.2 - The Binary Numbering System1.1.3 - Binary Formats1.2 - Data Organization1.2.1 - Bits1.2.2 - Nibbles1.2.3 - Bytes1.2.4 - Words1.2.5 - Double Words1.3 - The Hexadecimal Numbering System1.4 - Arithmetic Operations on Binary and Hexadecimal Numbers1.5 - Logical Operations on Bits1.6 - Logical Operations on Binary Numbers and Bit Strings1.7 - Signed and Unsigned Numbers1.8 - Sign and Zero Extension1.9 - Shifts and Rotates1.10 - Bit Fields and Packed Data1.11 - The ASCII Character Set1.12 Summary1.13 Laboratory Exercises1.13.1 Installing the Software1.13.2 Data Conversion Exercises1.13.3 Logical Operations Exercises1.13.4 Sign and Zero Extension Exercises1.13.5 Packed Data Exercises1.14 Questions1.15 Programming ProjectsChapter Two - Boolean Algebra2.0 - Chapter Overview2.1 - Boolean Algebra2.2 - Boolean Functions and Truth Tables2.3 - Algebraic Manipulation of Boolean Expressions2.4 - Canonical Forms2.5 - Simplification of Boolean Functions2.6 - What Does This Have To Do With Computers, Anyway?2.6.1 - Correspondence Between Electronic Circuits and Boolean Functions2.6.2 - Combinatorial Circuits2.6.3 - Sequential and Clocked Logic2.7 - Okay, What Does It Have To Do With Programming, Then?2.8 - Generic Boolean Functions2.9 Laboratory Exercises<

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值