我想將arraylist「測試」傳遞給「sortArray」方法並返回它,但我不斷收到錯誤。這是我的代碼,請你幫忙嗎?瞭解「缺少方法體」錯誤
我收到以下錯誤 「失蹤法體」
import java.util.Random;
import java.util.ArrayList;
public class SortingArrayListSD
{
public static void main(String[] args)
{
ArrayList<Integer> test = new ArrayList<>();
Random r = new Random();
int largest = 0, indexnumber = 0;
for (int s = 0 ; s < 10; s++)
{
test.add(1 + r.nextInt(99));
}
System.out.println("ArrayList Before: " + test);
test = SortArray(test);
System.out.println("ArrayList After: " + test);
}
public static ArrayList<Integer> SortArray(ArrayList<Integer> test);
{
ArrayList<Integer> test = new ArrayList<>();
for (int s = 1; s<test.size(); s++)
{
for (int a = 0; a<test.size(); a++)
{
if (test.get(s) > test.get(a))
{
int temp = test.get(s);
test.set(s, test.get(a));
test.set(a, temp);
}
}
}
return test;
}
}
兩個參數和局部變量被稱爲'test' .. – 2015-03-13 10:02:48
**公共靜態的ArrayList SortArray(ArrayList的試驗); ** 從該方法的末尾刪除分號。 另外,更改** ArrayList test = new ArrayList <>(); ** 至 test = new ArrayList <>(); –
Anshuman
2015-03-13 10:03:30