public static void readFromFile(){
List<Integer> putInList = new ArrayList<Integer>();
int jNum;
TextIO.readFile("jokerNums.txt");//read from a spesific file.
try{
do{
jNum = TextIO.getInt();
putInList.add(jNum);
} while(!TextIO.eof());// Test whether the next character in
//the current input source is an end-of-file
}
catch(IllegalArgumentException e){
}
TextIO.put(putInList);
}
我在do {} while循环中尝试了for循环但是它的无限。 仅举几个插入的数字是9785。 提前谢谢。
答案 0 :(得分:1)
for (int i = 0; !TextIO.eof(); i++){
int value = TextIO.getInt();
int targetIndex = (i/5)*5;
for (; targetIndex < putInList.size(); targetIndex++)
{
if(putInList.get(targetIndex)>value)
{
break;
}
}
putInList.add(targetIndex,value);
}