Angie A.

asked • 04/30/20

Need Help understanding method

public static double[][] readFile(java.io.File file)

throws java.io.FileNotFoundException

Reads from a file and returns a ragged array of doubles The maximum rows is 10 and the maximum columns for each row is 10

Each row in the file is separated by a new line Each element in the row is separated by a space Suggestion: You need to know how

many rows and how many columns there are for each row to create a ragged array. 1. Read the doubles from the file into an a

temporary array [10][10] of Strings which was initialized to nulls. 2. Find out how many rows there are (any row that has the first

element != null is a valid row) 3. Create the array based on the num of rows, i.e. double[][]array = new double[#rows][] 4.

Determine the number of columns for the first row (any element != null is a valid element) 5. Create the first row, i.e. array[0] =

new double[#columns] 6. Put the values from the temporary array into in the row (don't forget to convert from strings to doubles)

7. Repeat for all rows

Parameters:

file - the file to read from

Returns:

a two dimensional ragged (depending on data) array of doubles if the file is not empty, returns a null if file is empty

Throws:

java.io.FileNotFoundExceptio


I am stuck on understanding what this method wants

my code right now

public class TwoDimRaggedArrayUtility {

public static double[][] readFile (File file) throws FileNotFoundException{

Scanner sc = new Scanner(file);

}


}

1 Expert Answer

By:

Patrick B. answered • 05/02/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.