class Human {
constructor(name, age, sex, hobby) {
this.name = name;
this.age = age;
this.sex = sex;
this.hobby = hobby;
}
desc() {
const { name, age, sex, hobby } = this;
console.log(`我叫${ name }, 性别${ sex }, 爱好${ hobby }, 今年${ age }岁`);
}
eat() {
console.log('吧唧吧唧');
}
}
class FEEngineer extends Human {
constructor(name, age, sex, hobby, skill, salary) {
super(name, age, sex, hobby);
this.skill = skill;
this.salary = salary;
}
say() {
console.log(this.skill.join(','));
}
}
const feer = new FEEngineer(
'张四',
12,
'女',
'洗澡',
['es6', 'vue', 'react', 'webgl'],
'1k'
);
feer.eat();
代码练习:
返回空的二维数组: return new int[][]{};
public List<List<Integer>> shiftGrid(int[][] grid, int k) {
返回值:
List res=Arrays.asList(a);
return res;
作用:
这段代码将一个数组 a 转换为一个 List 集合 res,并返回该集合。具体来说,Arrays.asList(a) 方法将数组 a 转换为一个 List,然后将该 List 赋给变量 res。最后,函数返回变量 res。这样做的好处是可以方便地使用 List 的一些方法来操作数组中的元素,例如添加、删除、查找元素等。
```java
public List<List<Integer>> findIndex(int[][] nums, int target) {
List<List<Integer>> ret = new ArrayList<List<Integer>>();
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < nums[i].length; j++) {
if (nums[i][j] == target) {
List<Integer> index = new ArrayList<Integer>();
index.add(i);
index.add(j);
ret.add(index);
}
}
}
return ret;
}
该算法可以在一个二维数组中找到一个给定数字的索引,并将找到的索引放入另一个列表中:
List<Integer> index = new ArrayList<Integer>();
这段代码声明了一个类型为`ArrayList`的名为`index`的变量,该`ArrayList`对象可以存储整数类型的元素。
`ArrayList`是Java语言中的集合(Collection),可以动态地添加和删除元素,并且可以根据下标访问集合中的元素,与数组类似。
在这个算法中,`index`列表用于存储目标数字在二维数组中的索引。每当算法在遍历二维数组时发现目标数字,就会将它的索引添加到`index`列表中。在最后,算法返回这个列表,以供调用该算法的程序使用。
ret.add(index);
`ret`是一个`List`对象,它被声明为存储整数类型的`List`对象列表。在这个算法中,当你找到了目标数字的索引时,你会创建一个新的`List`对象`index`,将目标数字的索引添加到`index`中,最后将`index`添加到`ret`中。
按照上下文来理解,`ret`是用来存放数组中所有匹配的数字的索引的列表,而`index`则是用来存储单个数字的索引的列表,因此我们将`index`添加到`ret`,将所有匹配数字的索引存储在同一个列表中以返回给调用该算法的程序。