您的位置:首页 > 其它

合并数组并排序

2017-05-08 17:42 274 查看
将合并数组合并,并按升序排列

int s[] ={1,3,5,7,9,11,13,15,17,19};
int b[] ={2,4,5,6,7,10};
int [] c= new int[s.length+b.length];
System.arraycopy(s, 0, c, 0, s.length);
System.arraycopy(b, 0, c, s.length, b.length);
Arrays.sort(c);
for (int j = 0; j < c.length; j++) {
System.out.println(c[j]);

}
/* public static void arraycopy(Object src,
int srcPos,
Object dest,
int destPos,
int length)

Parameters:
src - the source array.
srcPos - starting position in the source array.
dest - the destination array.
destPos - starting position in the destination data.
length - the number of array elements to be copied.
*/


运行结果:

1

2

3

4

5

5

6

7

7

9

10

11

13

15

17

19
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数组 合并排序