자바 csv를 이용한 합 구하기 질문드립니다

조회수 809회

scanner 써서 아래의 csv 파일을 읽어와서 합계를 계산하는 프로그램을 작성해야하는데이미지

public class ScannerTest3 {

        public static void main(String[] args) throws Exception{

        Scanner sc1 = new Scanner(new File("C:\\Users\\dladnlwo\\Salaries.csv"));
        Scanner sc2 = null;

        int cnt = 0;
        int totalSum = 0;

    while(sc1.hasNextLine()) {

        String line=sc1.nextLine();
        sc2 = new Scanner(line).useDelimiter(" ");
        int sum = 0;

        while(sc2.hasNextInt()) {
            sum+=sc2.nextInt();
        }

        System.out.println(line+" sum="+sum);
        totalSum+=sum;
        cnt++;
        sc2.close();
    }
    System.out.println("Line : "+cnt+", Total : "+totalSum);
    sc1.close();
}

} 이미지 salary 열에 있는 값들을 합해서 출력해야하는데 위 코드로 돌리면 sum = 0 값만 나오고 어떻게 코드를 짜야하는지 모르겠습니다.

  • (•́ ✖ •̀)
    알 수 없는 사용자

1 답변

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)