注册 登录
编程论坛 J2EE论坛

请求帮助,数组问题,初学者

taoshucheng 发布于 2008-04-06 09:42, 744 次点击
两个一维数组合并成一个一维数组,并且按数值的大小,从大到小排列
public class xiti6_11
{
    public static void main(String args[])
    {
    int[] A={19,2,6,8,9};//声明三个数组
    int[] B={1,20,7,15,4};
    int[] C=new int[A.length+B.length];//定义一个数组用来存放两个数组
    //复制
    System.arraycopy(A, 0, C, 0, 5);
    System.arraycopy(B, 0, C, 5, 5);
    //排序
        for(int i=0;i<C.length-1;i++)
        {
        if(C[i]<C[i+1])
                {
                    int temp=C[i];
                    C[i]=C[i+1];
                    C[i+1]=temp;    
            }
        }    
    for(int j=0;j<C.length;j++)
    System.out.print(C[j]+"\t");       
     }
}
编译的时候有问题,我想应该是排序的时候错了,请大家帮忙提出
2 回复
#2
sunkaidong2008-04-06 11:16
public class xiti6_11
{
    public static void main(String args[])
    {
    int[] A={19,2,6,8,9};//声明三个数组
    int[] B={1,20,7,15,4};
    int[] C=new int[A.length+B.length];//定义一个数组用来存放两个数组
    //复制
    System.arraycopy(A, 0, C, 0, 5);
    System.arraycopy(B, 0, C, 5, 5);
    //排序
        for(int i=0;i<C.length-1;i++)
        {
        for(int j=0;j<C.length-1;j++)
        if(C[j]<C[j+1])
                {
                    int temp=C[j];
                    C[j]=C[j+1];
                    C[j+1]=temp;   
            }
        }   
    for(int j=0;j<C.length;j++)
    System.out.print(C[j]+"\t");      
     }
}
#3
taoshucheng2008-04-10 10:13
谢谢,十分感谢,我是数组输出的时候没有弄好,
1