int[] arr1 = {1,2,3,4,11};
int[] arr2 = {6,7,8,9,10};
int newLength = arr1.length + arr2.length;
int[] arr_target = new int[newLength];
//参数:源数组,源数组起始位置,目标数组,目标数组起始位置,复制长度
System.arraycopy(arr1, 0, arr_target, 0, arr1.length);
System.arraycopy(arr2, 0, arr_target, arr1.length, arr2.length);
//输出合并后数组
for (int i : arr_target) {
System.out.println(i);
}
//排序
Arrays.sort(arr_target);
//输出排序数组
for (int i : arr_target) {
System.out.println(i);
}
//逆序
int[] arr_reverse = new int[newLength];
int flag = 0;
for (int i : arr_target) {
arr_reverse[newLength - flag - 1] = i;
flag++;
}
//输出逆序数组
for (int i : arr_reverse) {
System.out.println(i);
}
数组合并不一定非得遍历
具体的输出题主自己再修改吧
public static void main(String[] args) {
int [] a={10,20,30};
int [] b={40,50,60};
int [] c = new int[a.length+b.length];
for(int i=0;iif(i c[i]=a[i];
}else{
c[i]=b[i-a.length];
}
}
for(int i =0 ;iSystem.out.print(c[i]+" ");
}
System.out.println();
System.out.print("逆序后(冒泡排序):");
int temp;
for(int i=0 ;ifor(int j=i;j {
if(c[j]>c[i]){
temp = c[i];
c[i] = c[j];
c[j] = temp;
}
}
for(int i =0 ;iSystem.out.print(c[i]+" ");
}
}
先用循环,将2个数组合并起来。然后用冒泡排序。