我沒有在年齡段寫過java,而且我知道我的問題非常簡單,但我不能爲我的生活找出錯誤。不能在同一個java類中調用方法
我試圖找到一個數組中的最小數字,使用下面的代碼。該算法是正確的,但我得到試圖在最後的print語句使用它時,一個錯誤
package runtime;
import java.util.ArrayList;
public class app {
/**
* @param args the command line arguments
*/
public int findSmallElement(ArrayList<Integer> num)
{
int smElement;
smElement= num.get(0);
for(int i=0; i<num.size() ; i++)
if(num.get(i) < smElement)
smElement=num.get(i);
return smElement;
}
public static void main(String[] args) {
ArrayList<Object> num = new ArrayList<Object>();
num.add(100);
num.add(80);
num.add(40);
num.add(20);
num.add(60);
System.out.println("The size of the list is " +num.size());
System.out.println(num.findSmallElement());
}
}