美好的一天!這個程序應該排序文件中的前n個單詞。當我調用mergeSort_srt方法時,請幫助我傳遞參數。當我運行這個時,控制檯說合併排序中的參數傳遞
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method mergeSort_srt(int[], int, int) in the type SortingAnalysis is not applicable for the arguments (String[], int, int)
我是新來編程expecially在Java語言,我很困惑。請幫幫我。儘管我想自己找到這個錯誤,但我不能,因爲我對這些東西一無所知,我需要真實的人幫助,而不僅僅是通過在線閱讀教程。非常感謝你!
import java.io.*;
import java.util.*;
public class SortingAnalysis {
public static void mergeSort_srt(int array[],int lo, int n){
int low = lo;
int high = n;
if (low >= high) {
return;
}
int middle = (low + high)/2;
mergeSort_srt(array, low, middle);
mergeSort_srt(array, middle + 1, high);
int end_low = middle;
int start_high = middle + 1;
while ((lo <= end_low) && (start_high <= high)) {
if (array[low] < array[start_high]) {
low++;
} else {
int Temp = array[start_high];
for (int k = start_high- 1; k >= low; k--) {
array[k+1] = array[k];
}
array[low] = Temp;
low++;
end_low++;
start_high++;
}
}
}
public static void main(String[] args) {
final int NO_OF_WORDS = 10000;
try {
Scanner file = new Scanner(new File(args[0]));
String[] words = new String[NO_OF_WORDS];
int i = 0;
while(file.hasNext() && i < NO_OF_WORDS) {
words[i] = file.next();
i++;
}
long start = System.currentTimeMillis();
mergeSort_srt(words, 0, words.length-1);
long end = System.currentTimeMillis();
System.out.println("Sorted Words: ");
for(int j = 0; j < words.length; j++) {
System.out.println(words[j]);
}
System.out.print("Running time: " + (end - start) + "ms");
}
catch(SecurityException securityException) {
System.err.println("You do not have proper privilege to access the files.");
System.exit(1);
}
catch(FileNotFoundException fileNotFoundException) {
System.err.println("Error accessing file");
System.exit(1);
}
}
}
哎呀,我很抱歉,我只是從另一個窗口複製粘貼錯誤。感謝您的認可!但那真的是mergeSort_srt。我真正的問題是參數的傳遞。 – 2012-07-08 13:13:55
@FirstLady,我根據您的更改更新了我的答案。 – 2012-07-08 13:21:14