import java.util.*;
class Pai
{
int z=0;
void paixu(ArrayList list,ArrayList helper)
{
for(int i=3;i>0;i--)
{
for(int j=0;j*i<list.size();j++)
{
helper[j] = list[i*j];
for(int n=0;n<j;n++)
{
for(int m=0;m<n;m++)
{
z=helper[m+1];
helper[m+1]=helper[m];
helper[m]=z;
}
}
}
}
}

}class PaiTest
{
ArrayList<int> List = new ArrayList();
ArrayList<int> helper = new ArrayList();
List.add(1);List.add(8);List.add(111);List.add(53);List.add(61);
List.add(139);List.add(229);List.add(85);List.add(54);List.add(97);
public static void main(String [] args)
{
Pai p=new Pai();
p.paixu(List,helper);
for(int i;i<List.size();i++)
System.out.println("排列的顺序是:"+p.List[i]);
}
}我在编译的时候,提示我"List.add(1);"需要标识符,请问各位这是为什么,在线等.

解决方案 »

  1.   

    汗~都不明白你要排序非要这么麻烦吗?这是你的错误:
    1.ArrayList <Integer> List = new ArrayList(); 
     ArrayList <Integer> helper = new ArrayList(); 2.z人类型不对3.z=helper[m+1]; 
    helper[m+1]=helper[m]; 
    helper[m]=z; 
    这是什么意思????4.helper[j] = list[i*j]; 
    这样可以吗?本人建义:
    JAVA里有个排序的方法Arrays.sort(a) 是按从小到大排的,a为一数组从大一小排的
    int a[]={1,3,2,5,.....};
    Arrays.sort(a);//从小到大排列
    int b[]=new int[a.length];
    for(int i=0;i<a.length;i++){
        b[i]=a[a.length-i-1];
    }
    b就是你要的降序排列你参考一下吧,希望对你有帮助。
      

  2.   

    1、泛型里面不能用 基本类型啊
    2、helper[j]
    错误比较多,建议用myeclipse看看
      

  3.   

    看到3个FOR循环的时候,我已经不想看了。