Statement of Completion#03096040
Other Examples
easy
AP CS A - Unit 1 - Primitive Types
Resolution
Activities
In [ ]:
In [ ]:
In [ ]:
1. Implement the add
function¶
In [7]:
int add(int x, int y) {
// Your code here
return x + y;
}
Try it by yourself:
In this case, 2 + 3 should be 5:
In [8]:
add(2, 3)
Out[8]:
5
In [9]:
add(9, 1)
Out[9]:
10
In [1]:
public static void changeArray(int[] arr)
{
for (int i = 0; i < arr.length - 1; i++)
{
arr[i] = arr[i + 1];
}
arr[arr.length - 1] = arr[0];
}
public static void changeMatrix(int[][] mat)
{
for (int i = 0; i < mat.length; i++)
{
changeArray(mat[i]);
}
}
In [2]:
int[][] mat = {
{1, 2, 3, 4},
{5, 6, 7, 8}
};
In [3]:
changeMatrix(mat)
In [5]:
System.out.println(java.util.Arrays.deepToString(mat));
[[2, 3, 4, 2], [6, 7, 8, 6]]
In [6]:
java.util.Arrays.deepToString(mat)
Out[6]:
[[2, 3, 4, 2], [6, 7, 8, 6]]
In [ ]: