错误太多,惨不忍睹。
- public class Test3 {
- public static void main(String[] args) {
- int[] arr = new int[20];
- for (int i = 0; i < arr.length; i++) {
- arr[i] = i;
- }
- int index = 5;
- int[] result = remove(arr, index);
- System.out.println(arr.length);
- System.out.println(result.length);
- }
- public static int[] remove(int[] arr, int index) {
- int[] temp = new int[arr.length - 1];
- for (int i = 0; i < temp.length; i++) {
- if (i < index) {
- temp[i] = arr[i];
- } else {
- temp[i] = arr[i + 1];
- }
- }
- return temp;
- }
- }
复制代码 |