2014-01-18 73 views

回答

1

在方法Read_Data(...)中,在執行操作之前,您正在增加c(您使用0初始化的值)的值。您必須在while-loop年底增加它:

while ((text = readFile.readLine()) != null){ 
    // ... your stuff 
    // ... 
    c += 1; // At the end 
} 

編輯:

displayData(...)for初始化條件值是錯誤的方法。嘗試改變該行

for (int i = 1; i <= dc; i++) { 

for (int i = 0; i < dc; i++) { 

編輯2:

bestSeller(...)方法要從0迭代j100(陣列長度)。這會導致異常,您可能想要使用實際讀取的數據數量。

for (int j = 0; j < sortC - 1; j++) { 
    for (int k = j + 1; k < sortC; k++) { 

有了這個變化我得到,爲選項3(暢銷書),預期的輸出(在.txt修改音量值之後)

POP  Beatles8  Let It Be  18.0 
POP  Beatles7  Let It Be  17.0 
POP  Beatles6  Let It Be  16.0 
POP  Beatles5  Let It Be  15.0 
POP  Beatles1  Let It Be  13.0 
POP  Beatles2  Let It Be  12.0 
POP  Beatles3  Let It Be  11.0 
POP  Beatles4  Let It Be  10.0 
+0

好的,我提出的計數器到端並且Best_Seller/bestSeller方法中的第一個值不再爲空。但是,readData方法現在不起作用。我得到另一個異常錯誤。 – user2913362

+0

您能否提供您正在讀取數據的文件? – Christian

+0

我編輯了我原來的帖子。 – user2913362

相關問題