나는, 그들은 모두 서로 다른 라인 등의 ArrayList는에서 읽고 있지 제대로
에 ArrayList에 & 나는 그것이 숫자 파일 내의 & 전체에서 읽을 수 있지만, 그것은 단지 파일 내에서 마지막 숫자를 출력되어있는 한Here is my code, thanks in advance:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListOfNumbers {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
Scanner Scan = new Scanner (new File("numbers.txt"));
int sumOf = 0;
for(int i=0; i < list.size(); i++){
sumOf = sumOf + list.get(i);
}
//while scanning add sum to ArrayList List
while (Scan.hasNext())
{
sumOf = Scan.nextInt();
list.add(sumOf);
}
//print the array list
System.out.println(sumOf);
Scan.close();
}
}