【发布时间】:2014-03-02 18:58:13
【问题描述】:
我收到一条错误消息,提示编译器找不到我的变量“complexArray”,但我不知道为什么。如何修复我的程序,使其返回从文件中读取的复数数组?
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;
}
【问题讨论】:
标签: java arrays return try-catch