1
내 프로그램은 행의 모든 데이터를 인쇄하지만 다른 모든 행만 인쇄합니다. 나는 그것이 "nextLine"과 관련이 있다는 것을 알고 있지만 문제의 원인을 찾을 수는 없습니다. (doc here 참조)프로그램이 다른 행을 건너 뜁니다. 이유는 확실하지 않습니다.
import java.io.*;
import java.util.*;
public class hw2
{
public static void main (String[] args) throws Exception
{
String carrier;
int flights;
int lateflights;
int ratio;
String[][] flightData= new String [221][3];
String[] temp;
File file = new File ("delayed.csv");
Scanner csvScan = new Scanner(file);
int c = 0;
while ((csvScan.nextLine()) != null){
String s = csvScan.nextLine();
temp = s.split(",");
for(int i =0; i < temp.length ; i++)
System.out.println(temp[i]);
flightData[c][0] = temp[1];
flightData[c][1] = temp[6];
flightData[c][2] = temp[7];
c = c+1;
}
}
}
** 마른 세수 ** 년 OFC를. +1 이것은 정답입니다. – Brian
예, while 루프의 테스트는 실제로 스캐너에서 라인을 제거합니다. hasNextLine()으로 변경하면 줄 건너 뛰기가 중단됩니다. – digidigo