JAVA程序。。。定义两个数组,首先把两个数组合并成一个数组,然后把新数组中的元素逆序排列
2个回答
展开全部
public static void main(String[] args) {
Integer[] a = { 45, 9, 8 };
Integer[] b = { 3, 6, 5, 9 };
Integer[] result = new Integer[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, a.length, b.length);
//自定义排序
Comparator<Integer> comparator = 册昌new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
// 如果n1小于n2,我们就返回正值,如果n1大于n2我没悉们就返回负值,
// 这样颠倒一下,就可以实现枯姿乎反向排序了
if (o1 < o2) {
return 1;
} else if (o1 > o2) {
return -1;
} else {
return 0;
}
}
};
Arrays.sort(result,comparator);
System.out.println(Arrays.toString(result));
}
展开全部
package com.dubo;
public class Sort {
public static void main(String[] args) {
int a[] = { 1, 5, 3 ,4};
int b[] = { 2, 9, 8 };
// 组合两个戚睁数组
int t[] = joinAndSort(a, b);
String result = "";
for (int i = 0; i <培喊 t.length; i++) {
result = result + t[i];
}
System.out.println(result);
}
private static int[] joinAndSort(int[] a, int[] b) {
int aLen = a.length, bLen = b.length;
int[] c = new int[aLen + bLen];
int[] t = new int[aLen + bLen];
for (int i = 0; i < aLen; i++) {
c[i] = a[i];
}
for (int j = 0; j < bLen; j++) {
c[j + aLen] = b[j];
}
for (int p = 0; p < c.length; p++) {
t[p] = c[c.length - p - 1];
}
return t;
}
}
求采高中岁纳
public class Sort {
public static void main(String[] args) {
int a[] = { 1, 5, 3 ,4};
int b[] = { 2, 9, 8 };
// 组合两个戚睁数组
int t[] = joinAndSort(a, b);
String result = "";
for (int i = 0; i <培喊 t.length; i++) {
result = result + t[i];
}
System.out.println(result);
}
private static int[] joinAndSort(int[] a, int[] b) {
int aLen = a.length, bLen = b.length;
int[] c = new int[aLen + bLen];
int[] t = new int[aLen + bLen];
for (int i = 0; i < aLen; i++) {
c[i] = a[i];
}
for (int j = 0; j < bLen; j++) {
c[j + aLen] = b[j];
}
for (int p = 0; p < c.length; p++) {
t[p] = c[c.length - p - 1];
}
return t;
}
}
求采高中岁纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询