import java.util.Random;
public class Example3 {
public static void main(String[] args) {
int aLength = getRandom(5,10);
int bLength = getRandom(5,10);
int a [] = new int[aLength];
int b [] = new int[bLength];
int c [] = new int[aLength+bLength];
for(int i = 0 ; i < aLength ; i++){
a[i] = (int) (Math.random() * 100);
}
for(int i = 0 ; i < bLength ; i++){
b[i] = (int) (Math.random() * 100);
}
System.out.println("a:");
//把内容打印出来
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.println("\nb:");
//把内容打印出来
for (int i = 0; i < b.length; i++) {
System.out.print(b[i] + " ");
}
//方法二: System.arraycopy(src, srcPos, dest, destPos, length)
//src: 源数组
//srcPos: 从源数组复制数据的起始位置
//dest: 目标数组
//destPos: 复制到目标数组的启始位置
//length: 复制的长度
System.arraycopy(a, 0, c, 0, aLength);
System.arraycopy(b, 0, c, aLength, bLength);
System.out.println("\nc:");
//把内容打印出来
for (int i = 0; i < c.length; i++) {
System.out.print(c[i] + " ");
}
}
public static int getRandom(int min, int max){
Random random = new Random();
int s = random.nextInt(max) % (max - min + 1) + min;
return s;
}
}
标签:java,随机数,int,System,length,数组,aLength,out
来源: https://www.cnblogs.com/pangchunlei/p/14172772.html