Return an int array length 3 containing the first 3 digits of pi, {3, 1, 4}.
时间: 2024-01-12 17:02:43 浏览: 153
Sure, here's the code in Java:
```
int[] piDigits = {3, 1, 4};
return piDigits;
```
This will create an integer array of length 3 and initialize it with the values 3, 1, and 4, which are the first three digits of pi.
相关问题
Given an array of ints, return a new array length 2 containing the first and last elements from the original array. The original array will be length 1 or more.
Sure, here's the solution in Python:
```python
def make_ends(nums):
return [nums[0], nums[-1]]
```
This function takes an input array `nums` and returns a new array containing the first and last elements of the input array. We use the `[0]` index to access the first element of the array, and the `[-1]` index to access the last element of the array.
Given 2 int arrays, a and b, each length 3, return a new array length 2 containing their middle elements.
以下是 Python 代码实现:
```python
def middle_way(a, b):
return [a[1], b[1]]
```
这个函数接受两个长度为 3 的整数数组 `a` 和 `b` 作为输入,返回一个新的长度为 2 的数组,其中包含两个输入数组的中间元素。
例如,`middle_way([1, 2, 3], [4, 5, 6])` 的返回值为 `[2, 5]`。
阅读全文