求大侠看看,哪里错了?
程序代码:
package e; public class NumList { private int [] numList=null; private int pos=0; public void setLength(int length){ numList=new int [length]; } private int getPos(int value){ int curPos; int i; for( i=pos-1;i>=0;i--) if(numList [i]>value) numList[i+1]=numList[i]; else break; curPos=i+1; return curPos; } public void AddValue(int value){ if(pos<numList.length){ int insertPos=getPos(value); numList[insertPos]=value; pos++; } } public int getValue(int pos){ return numList[pos]; } public String toString(){ String data=" "; for(int singleData:numList){ data=data + singleData + " "; } return data; } public void main(String [] args){ setLength(5); AddValue(1); AddValue(2); AddValue(3); AddValue(4); System.out.println(getValue(3)); System.out.println(toString()); } }