컴파일러에서 "complexArray"변수를 찾을 수 없다는 오류가 발생하지만 이유를 알 수 없습니다. 파일에서 읽은 복소수 배열을 반환하도록 프로그램을 수정하려면 어떻게해야합니까?Java : 로컬 변수 범위
public static Complex[] parseFromFile(String fileName) {
int numOfComplex = 0;
try {
Scanner sc = new Scanner(new File(fileName));
String firstLine = sc.nextLine();
firstLine = firstLine.trim();
numOfComplex = Integer.parseInt(firstLine);
Complex[] complexArray = new Complex[numOfComplex];
for (int i = 0; i < numOfComplex; i++) {
String nextLine = sc.nextLine();
nextLine = nextLine.trim();
complexArray[i] = parseComplex(nextLine);
}
}
catch(Exception e) {
}
return complexArray;
}
null로 선언하면 null로 반환됩니다. 어떤 이유로 배열이 try/catch 블록 내에서 변경되지 않는다. – user3277742