Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>// from your main method String fname = "data.txt"; readData (fname); // the method being called public static void readData (String data[][]){ BufferedReader br = new BufferedReader(new FileReader(data)); </code></pre> <p>We have an incompatibility here.</p> <ul> <li>fname is a String</li> <li>The method takes a String[] as a parameter. </li> <li>the constructor newFileReader() takes a string, not 2d array.</li> </ul> <p>All of these three should be the same data type. </p> <blockquote> <p>How can I separate each "receipt" with zero (like shown in the image link above)?</p> </blockquote> <p>You don't have to. You have to READ from that file with the zeros in it.<br> I would recommend you write a method something like this:</p> <p>public double[] readOneReceipt(BufferedReader reader);</p> <p>This method should</p> <ul> <li>Read line by line until it encounters a 0 entry</li> <li>for each entry it reads convert the value into a number (double?) </li> <li>Store the number in a temporary structure. </li> <li>When you encounter the "0", create a new array of the correct size and copy the read values into it.</li> </ul> <blockquote> <p>How can I write the output into a separate file? </p> </blockquote> <p>With a java.io.FileWriter</p> <p>The hardest bit of this IMO is the fact that you are told to store the data in a 2d array, but you don't exactly what size to make the array until you've read the data. Which means that you either use a temporary dynamic structure, or read the file twice - once to find out how many receipts there are so that you can make the array, and then again to actually read the receipt data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload