数组补充
当我们对数组进行取值时候,有了一种简单的方式和方法,那就是foreach,数组不单单是指普通的数组,数组也有面数组,立体数组等等。
Java中有三种注释方式,第一种// 第二种/* */ 第三种 /** */ ,第三种注释也被称作JavaDoc注释,这种方式也是官方文档的写作方式。我们写的代码都可以通过注释写成jar包让其他人看。
文档注释中包含很多特定的注释信息,
@author:表示源代码的作者名称。
@version:描述类的软件版本。
@see:创建一个“参见”XX条目的链接,如类、方法、变量等。
@param:用于描述方法的形式参数。
@return:用于描述方法的返回值。
@exception:被方法所用,列出抛出的异常。
……
数组的操作还包括冒泡排序等等。
冒泡排序格式
for (int i = 0; i < 数组长度 - 1; i++) {
for (int j = 0; j < 数组长度 - 1; j++) {
if (num[j] > num[j + 1]) {
中间存储容器 = num[j];
num[j] = num[j + 1];
num[j + 1] = 中间的存储容器;
}
}
for (int j = 0; j < 数组长度 - 1; j++) {
if (num[j] > num[j + 1]) {
中间存储容器 = num[j];
num[j] = num[j + 1];
num[j + 1] = 中间的存储容器;
}
}
}
添加数据到数组中
public static add(int element) {
int size = 0;
size++;
int length = arr.length;
if (size > length) {
arr = Arrays.copyOf(arr, size);
}
arr[size - 1] = element;
length = arr.length;
}
int size = 0;
size++;
int length = arr.length;
if (size > length) {
arr = Arrays.copyOf(arr, size);
}
arr[size - 1] = element;
length = arr.length;
}