public class BubbleSort
{ static String printArray(int[] a)
{ String result=""; 
for(int i=0;i<a.length;i++) result+=a[1]+" "; 
return result; 

static int[] bubbleSort(int[] a)
{ int t; 
for(int i=0;i<a.length;i++) 

for(int j=0;j<a.length-i-1;j++) 
//升序排列用大于,降序排列用小于,此处为降序排列。 
if(a[j]<a[j+1]);} 
return a; 

public static void main(String args[]) 

int []a=; 
System.out.println("排序前的数组\n"+printArray(a)); 
a=bubbleSort(a); 
System.out.println("排序后的数组\n"+printArray(a)); 

}
 
然后偶编译时候提示我 illegal start of expression 
int []a=;
我是新学的,完全是JAVA文盲。有知道的说一下吧 感激下先

解决方案 »

  1.   

    我把刚才的错误改成了int a[]={20,3,-2,60,15};
    然后java 了一下生成的class 然后得到的结果是
    排序前的数组3 3 3 3 3
    排序后的数组3 3 3 3 3 
    不知道错误再哪里 可以告诉我吗 知道的?
      

  2.   

    int []a=;这句是非法声明,在java中要动态接收参数要用I/O方法:BufferedReader br=new BufferedReader(new InputStreamReader(System.in))说实话在java中动态输入比较烦琐
      

  3.   

    public static void bubbleSort(int[] array)
        {
            int temp,i,j,len=array.length-1;
            int bottom= array.length - 1;
            boolean exchanged = true;
            while (exchanged)//if no exchange,then sort over
            {
                exchanged = false;
                for (i = 0; i < bottom ; i++)
                {
                    if (array[i] > array[i + 1])
                    {
                        //exchange i and i+1
                        //max down
                        temp = array[i];
                        array[i] = array[i + 1];
                        array[i + 1] = temp;
                        //has changed
                        exchanged = true;
                    }
                }
                bottom--; //this,array[botton] is the max
            }
        }
      

  4.   

    BufferedReader br=new BufferedReader(new InputStreamReader(System.in))
    这个可不可以按照我的实现说的具体点啊
    我把你这个给添加到了 int []a=后面不对哦
      

  5.   

    public class BubbleSort {
    static String printArray(int[] a) {
    String result = "";
    for (int i = 0; i < a.length; i++)
    result += a[i] + " ";
    return result;
    }
    static int[] bubbleSort(int[] a) {
    boolean change = false;
    for (int i = 0; i < a.length; i++) {
    for (int j = 0; j < a.length - i - 1; j++)
    // 升序排列用大于,降序排列用小于,此处为降序排列。
    if (a[j] > a[j + 1]) {
    int temp = a[j + 1];
    a[j + 1] = a[j];
    a[j] = temp;
    change = true;
    }
    if (!change)
    break;
    }
    return a;
    } /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    int[] a = {20, 3, -2, 60, 15}; System.out.println("排序前的数组\n" + printArray(a));
    a = bubbleSort(a);
    System.out.println("排序后的数组\n" + printArray(a)); }}
      

  6.   

    你的主要错误是在打印函数中的result += a[i] + " ";你写成了a[1],当然打印出来都是3了