-
Notifications
You must be signed in to change notification settings - Fork 0
/
twoArray.sol
43 lines (30 loc) · 951 Bytes
/
twoArray.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;
contract twoArray {
// 2代表是二维数组中的元素个数
// 3是代表一维数组中的元素个数
// 正常取值跟别的语法相同 正常取值
uint[2][3] public grade = [[1,2],[3,4],[5,6]];
function getOneArrayLength() view public returns(uint) {
return grade.length; // 3
}
function getTwoArrayLength() view public returns(uint) {
return grade[2].length; // 2
}
function getcontent() view public returns(uint[2][3] memory) {
return grade;
}
function add() view public returns(uint) {
uint sum = 0;
for (uint i = 0; i < grade.length; i++){
for (uint j = 0; j < grade[i].length; j++) {
// 求和
sum += grade[i][j];
}
}
return sum;
}
function changeGrade() public{
grade[2][1] = 100;
}
}