Results 21 to 23 of 23
- 02-18-2009, 05:24 PM #21
Member
- Join Date
- Feb 2009
- Posts
- 24
- Rep Power
- 0
- 02-18-2009, 05:34 PM #22
No... what I said was the it will loop only once (because the the return statement is at the end of the while statement). It will execute any code in the while loop, but only once.So, you say that the while loop will only read the first line...correct ?
So I ask again... where should the return statement be moved to?
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 02-18-2009, 05:35 PM #23
Member
- Join Date
- Feb 2009
- Posts
- 24
- Rep Power
- 0
I made the following change in the code, by taking the return statement outside the while loop.
But, it shows the following error:-Java Code:public static double[] fileread(String fName) throws IOException { String thisLine; //string variable to take each record at a time int count=0; int x=0; double dblArray[]; FileInputStream fis = new FileInputStream(fName); //A FileInputStream obtains input from a file DataInputStream myInput = new DataInputStream(fis); /*data input stream lets an application read primitive Java data types from an underlying input stream*/ while ((thisLine = myInput.readLine()) != null) { //beginning of outer while loop String[] result = thisLine.split(","); dblArray = new double[result.length]; for (x=0; x<result.length; x++) { /*return result[x];*/ dblArray[x] = Double.parseDouble(result[x]); } } return dblArray; }
C:\Users\Jaimin\Documents\JCreator Pro\MyProjects\finalcode2.java:69: variable dblArray might not have been initialized
return dblArray;
I have already declared dblArray variable in the beginning of the method. However, an error like above is shown. why ?
Similar Threads
-
Combining Individual Sounds - Urgent
By JDCAce in forum Advanced JavaReplies: 4Last Post: 12-05-2008, 05:17 AM -
How to get objects to interact without inheritence in separate classes?
By Fliz in forum New To JavaReplies: 1Last Post: 11-18-2008, 04:48 PM -
Help combining loops into 1 program.
By kewlgeye in forum New To JavaReplies: 5Last Post: 04-22-2008, 09:58 AM -
Hash table with separate chaining
By Java Tip in forum java.langReplies: 0Last Post: 04-12-2008, 08:42 PM -
I'm trying to add a separate dialog to a Java program...
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:26 AM


LinkBack URL
About LinkBacks

Bookmarks