错误:类,接口或枚举预期冒泡排序

时间:2017-01-25 11:49:41

标签: java sorting enums interface

我目前在以下代码中遇到问题。该程序的目标是使用冒泡排序对列出的项目进行排序。

import java.util.Scanner;                               //Library for scanner input

class JavaAssignmentTwo{                                //Start of java program

    public static void main(String args[]){             //Main section of the program
      int item;                                         //loop variable 

      String prodname[] = 
      {"Coke", "Red Bull", "7Up", "Water", "Fanta", "Sprite", "Tayto Crisps"};  //Products for sale


      System.out.print("\t\t    Sorting Carrefour Stock.");             
      System.out.print("\n\t  ---------------------------\n\n");    
      System.out.print("\n\tOriginal order\n\n");
      for (item = 0; item<prodname.length; item++){
        System.out.printf("%-3d%-15s\n",(item+1),prodname[item]);   
      } 
      System.out.print("\n\n\tSorted order\n\n");
      Easy_Sort_routines.Bubble_sort(prodname, true);

      Easy_Sort_routine.display_array(prodname);

    }

}
// --------------------------------------------------------------
// BUBBLE SORT for an array of strings
// asds = true => ascending
public static void Bubble_sort(String ss[], boolean asds){
  int zzz, jjj;
  String temp = "";

  for (jjj=0; jjj<ss.length; jjj++){
    for (zzz=1; zzz<ss.length; zzz++){
      if (asds){
        if (ss[zzz-1].compareTo(ss[zzz]) >0){    // ascending
          temp = ss[zzz-1];       // swap elements
          ss[zzz-1] = ss[zzz];
          ss[zzz] = temp;
        }
        else
          if (ss[zzz].compareTo(ss[zzz]) <0){    // descending
            temp = ss[zzz-1];       // swap elements
            ss[zzz-1] = ss[zzz];
            ss[zzz] = temp;
          }                    // end of descending if
        }   
      }      // end of zzz loop
  }       // end of jjj loop
}         // end of Bub_sort

// --------------------------------------------------------------
// Display array routine

public static void display_array(String ss[]){
 int index;

 for (index = 0; index<ss.length; index++){
  System.out.printf("%-3d%-15s\n",(index+1),ss[index]);
    }
  }
}

我遇到的错误是错误:class,interface或enum expect。我还不熟悉java,我不知道造成这个问题的原因是什么?如果有人能指出我正确的方向,请。

1 个答案:

答案 0 :(得分:0)

请参阅此代码段中的评论:

      // ...
      Easy_Sort_routine.display_array(prodname);

    }

} // <=== Remove this! It closes your class body.
// --------------------------------------------------------------
// BUBBLE SORT for an array of strings