首页 技术 正文
技术 2022年11月9日
0 收藏 392 点赞 4,680 浏览 873 个字

1.数组
格式:数据类型 [ ] 数据名称 = new 数据类型 [ ] { };
2.初始化
静态初始化(已知要开多少个房间来存储数据)

int[ ] a =new int[ ] {12,32,54,64};
System.out.println(a[0]);
【12】

动态初始化(未知数据个数,需要预留空间 )
int[ ] b =new int [10];//预留了十个空位
System.out.println(b[11]); //超过预留空间个数则会报错(称为数组越界)
【ArrayIndexOutOfBoundsException】
b[0]=11;
b[1]=12;
System.out.println(b[0]);
System.out.println(b[1]);
【11】
【12】
String[ ] c=new String[10];
c[0]="hhh";
c[3]="asdf";
System.out.println(c[0]);
System.out.println(c[3]);
【hhh】
【asdf】
3.数组的长度报数
4.遍历数组
加减数据,输出也随之变化
5.数组的练习:整个数组的输出
特别注意: 数组中数据的长度比 [ ] 的数字多一
思考步骤:
1.输出“[”
2.全部输出每一位数据
3.除最后一位数据外,其他每位数据后都要加“,”
4.输出“]”
【以不同的数据类型定义的数组】
6.数组的练习2:整个数组倒序输出
7.二维数组
法一:
int[] a = {1,2,3};
int[] b = {0,1,2,3};
int[] c = {4,5,6};
int[][] two = new int[][] {a,b,c};
System.out.println(two.length);
【3】
法二:
int[][] two2 = new int[][] {
{4,5,6},
{3,4,5,6},
{4,5,6,7}
};
System.out.println(two2.length);
【3】
8.获取二维数组的值
System.out.print(two2[0][0]);
【4】
System.out.print(two2[1][0]);
【3】
9.使用for循环简便二维数组的输出

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,027
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,518
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,365
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,146
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,780
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,857