/**
(int)(Math.random()*100)
上面的代码作用是用于获取0-100的随机数
Math.random()会得到一个0-1之间的浮点数,然后乘以100,并强转为整型即可
*/
/**
for each语句是java 中for语句的简化版本,
格式:
for(元素数据类型 元素变量:遍历对象)
{
//循环体内容
}
*/
///**
// * 数组的长度是不可变的,一旦分配好空间,是多长,不能增加也不能减少
// * 把一个数组的值,复制到另一个数组中
// *
// * System.out.println(src,srcPos,dest,destPos,length)
// *
// * src:源数组
// * srcPos:从源数组复制数据的起始位置
// * dest:目标数组
// * desrPos:复制到目标数组的起始位置
// * length:复制的长度
// *
// * */
//
//public class fuZhi {
// public static void main(String[] args){
// int a[] =new int[] {18,62,33,12,67};
// int b[] = new int[4];//分配了长度是3的空间,但是没有赋值
// //通过数组赋值把,a数组的前3位赋值到b数组
//
// //方法一:for循环
//
// for (int i = 0; i < b.length; i++){
// b[i] = a[i];
// }
//
// //方法二:System.arraycopy(srcPOs,dest,destPos,length)
// //src: 源数组
// //srcPos: 从源数组复制数据的起始位置
// //dest: 目标数组
// //destPos: 复制到目标数组的启始位置
// //length: 复制的长度
// System.arraycopy(a,0,b,0,4);
// //把内容打印出来
// for (int i = 0; i < b.length; i++){
// System.out.println(b[i] + " ");
// }
// }
//}
/**
* 需求:准备两个数组,两的长度都是5-10之间的随机数,并使用随机数初始这两个数组
* 向数组填充随机数的方法
* 准备第三个数组,第三发数组的长度是前两个的和,通过System.arraycopy把前两个数组合并到第三个数组中
*
* */
public class fuZhi{
public static void main(String[] args){
int[] a = new int[5];//定义出一个长度是5的空间,但是没有进行赋值,名字叫a
int[] b = new int[5];//定义出一个长度是5的空间,但是没有进行赋值,名字叫b
int[] c = new int[10];//定义出一个长度是5的空间,但是没有进行赋值,名字叫
for(int i =0;i<5;i++)
{
a[i] = (int)(Math.random()*100);//随机重0-100之间取出五个数,并强转为int类型,填充至a列表空间中
b[i] = (int)(Math.random()*100);//随机重0-100之间取出五个数,并强转为int类型,填充至b列表空间中
}
System.out.println("数组a的内容: ");
for(int each:a){
System.out.print(each+" ");//使用for each的方式将列表的数据进行遍历出来
}
System.out.println(); //打印一个换行的功能
System.out.println("数组b的内容: ");
for(int each:b){
System.out.print(each+" ");
}
System.arraycopy(a,0,c,0,5);//将a列表的数据复制进c列表
System.arraycopy(b,0,c,5,5);//将b列表的数据复制进c列表
System.out.println();
System.out.println("数组c的内容");
for (int each:c){
System.out.print(each+" ");
}//使用
}
}