Note that there are some explanatory texts on larger screens.

plurals
  1. POPrint formatting array values in loop?
    primarykey
    data
    text
    <p>I'm learning java on my own through a book and it has a diagram I should replicate through finding array values and looping to to display from a text file. I have all the fields printing just fine but I can't seem to separate them?</p> <p><img src="https://i.stack.imgur.com/5wDDk.png" alt="enter image description here"></p> <p>I have an idea of what too do but it's just not doing what I want..</p> <pre><code>public static void main(String[] args) { Scanner input = null; File empFile = new File("employeesSalesRep.txt"); String[][] empArray = new String[9][6]; try { input = new Scanner(empFile); for (int outer = 0; input.hasNext() == true; ++outer) { for (int inner = 0; inner &lt; empArray[outer].length; ++inner) { empArray[outer][inner] = input.next(); } if (empArray[0][4].equals("22")) { } } } catch (FileNotFoundException e) { System.out.println("Cannot find file. File must be in your PROJECT folder!"); System.out.println("System out print: " + e.getMessage()); System.err.println(e.getMessage()); System.exit(0); } finally { input.close(); } System.out.printf("%-13s", "Emp #"); System.out.printf("%-13s", "Last Name"); System.out.printf("%-13s", "First Name"); System.out.printf("%-13s", "MI"); System.out.printf("%-13s", "Sales Rep"); System.out.printf("%-13s", "Commision"); System.out.println(); System.out.printf("%-13s", "---------"); System.out.printf("%-13s", "---------"); System.out.printf("%-13s", "-----------"); System.out.printf("%-13s", "---------"); System.out.printf("%-13s", "----------"); System.out.printf("%-13s", "-----------"); System.out.println(); for (int x = 0; x &lt; empArray.length; ++x) { if (empArray[x][0] == null) break; for (int i = 0; i &lt; empArray[x].length; ++i) { System.out.printf("%-13s", empArray[x][i]); } System.out.println(); } } </code></pre> <p>I don't need a direct answer. Just some direction. Give me a piece to base my code off of and I'll do the rest. I really want to learn this.</p> <p>(Also any help in finding how to accumulate the totals would be great!)</p> <p>Thanks.</p> <p><strong>Edit:</strong> <br> I figured out the formatting part. But now I'm having trouble accumulating the values...</p> <p><img src="https://i.stack.imgur.com/kxaTm.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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