Java 练习题 给出两个数组 a:1,7,11,13,15,17,19;b 2,4,6,8,10

2025-03-31 06:41:49
推荐回答(4个)
回答1:

import java.util.*;
class Test{
    public static void main(String[] args){
        int[] a={1,7,11,13,15,17,19};
        int[] b={2,4,6,8,10};
        int[] c=new int[a.length+b.length];
        System.arraycopy(a,0,c,0,a.length);
        System.arraycopy(b,0,c,a.length,b.length);
        Arrays.sort(c);
        System.out.println(Arrays.toString(c));
    }
}

回答2:

public class Demo09 {
public static void main(String[] args) {
int a[] = new int[]{1, 7, 9, 11, 13,15, 17,19};
int b[] = new int[]{2, 4, 6, 8,10};
int c[]=new int [13];//计算好数组c所需大小
System.arraycopy(a,0,c,0,8);//使用arraycopy方法
System.arraycopy(b,0,c,8,5);
for(int i=0;iSystem.out.print(c[i]+" ");//循环遍历新数组
}
}
}

回答3:

c: 1,2,4,6,7,8,10,11,13,15,17,19

回答4:

package asd;
import java.util.Arrays;
public class gg {
public static void main(String[] args) {
String a="1,7,9,11,13,15,17,19,";
String b="2,4,6,8,10";
String s=a+b;
String[] c=s.split(",");
int t[] = new int [13];
for(int i=0;i<13;i++)
t[i]=Integer.parseInt(c[i]);
Arrays.sort(t);
System.out.printf(Arrays.toString(t));
}
}
附结果:[1, 2, 4, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19]