package org.company.project.test
import java.util.Arrays
import java.util.Random
import java.util.Scanner
public class ArraysCopy {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in)
System.out.println("随机数组请输入长度:")
int n = sc.nextInt()
sc.close()
int[] arr = new int[n]
Random ra = new Random()
for(int i=0
arr[i] = ra.nextInt(100)
}
System.out.println("arr:\n"+Arrays.toString(arr))
int[] arr1 = new int[n+1]
System.arraycopy(arr, 0, arr1, 0, arr.length)
System.out.println("arr扩容1个长度赋值给arr1:\n"+Arrays.toString(arr1))
arr = Arrays.copyOf(arr, n+2)
System.out.println("arr本身扩容2个长度:\n"+Arrays.toString(arr))
}
}