本帖最后由 GoodBoy123 于 2014-6-14 19:39 编辑
- 不用集合也能做:
- <DIV class=blockcode>
- <BLOCKQUOTE>public class Test {
- public static void main(String args [])
- {
- int str1[] = {2,9,6,8,3,4,2,6,7,0};
- int str2[] = {10,8,7,1,4,5,2,1,9,26};
- int size = str1.length + str2.length; //新数组的长度
- int str [] = new int [size];
- int index = 0;
- for(int i = 0; i < size; i++) //把两个数组都复制到新数组里.
- {
- if(i < str1.length) //复制str1到新数组
- str[i]= str1[i];
- else
- {
- if(index < str2.length)
- str[i] = str2[index++];
- } //复制str2到新数组
- }
- Arrays.sort(str); //API里的排主法
- //打印出来看看
- for(int i = 0; i < str.length; i++)
- {
- System.out.println(str[i]);
- }
- }
- }
复制代码
|