题解 | #有序序列合并#
有序序列合并
http://www.nowcoder.com/practice/a9e943b0dab142759807d0cfb6863897
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int[] aarr = new int[a];
int[] barr = new int[b];
for(int i = 0; i < aarr.length; i++) {
aarr[i] = scan.nextInt();
}
for(int i = 0; i < barr.length; i++) {
barr[i] = scan.nextInt();
}
//可以用数组存放aarr和barr这两个数组,再正序输出
int[] parr = new int[a + b];
System.arraycopy(aarr, 0, parr, 0, a);
System.arraycopy(barr, 0, parr, a, b);
//关于arraycopy的用法可以参照
//https://blog.csdn.net/Lilip_/article/details/124280524?spm=1001.2014.3001.5501
Arrays.sort(parr);
for(int i = 0; i < parr.length; i++) {
System.out.print(parr[i] + " ");
}
}
}
Java基础练习题 文章被收录于专栏
都是一些基础的语法题目,每天可以刷几道。