arrays - Java: Local variable scope -
i error saying compiler cannot find variable "complexarray" don't know why. how fix program returns array of complex numbers read file?
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]; (int = 0; < numofcomplex; i++) { string nextline = sc.nextline(); nextline = nextline.trim(); complexarray[i] = parsecomplex(nextline); } } catch(exception e) { } return complexarray; }
your complexarray variable declared inside try{} scope. declare before try statement.
complex[] complexarray = null;
Comments
Post a Comment