Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's some ideas about how I would do it.</p> <p>let's say you store your data in a 2d array of integers</p> <pre><code>int [] [] data = new int [rows] [columns] </code></pre> <p>so in this case columns are A, B, C etc.</p> <p>You need to iterate like this when searching the maximum:</p> <p><code>data[i][fix]</code> so the column is fixed and the row is changed in the loop</p> <p>in your example if you want to get the max of <code>A</code> and you use a 2d array like i advised, then:</p> <pre><code>int [] [] data = new int [3][3]; </code></pre> <p>then the set where you need to get the maximum for <code>A</code> from is <code>data [0][0]</code>, <code>data[1][0]</code> and <code>data[2][0]</code></p> <p>EDIT:</p> <p>Here's one possible solution for you.</p> <pre><code>//here is our data array. int [][] data = new int[3][]; //fill up with som random data data[0] = new int[]{10,20,4,5,56,87,9}; data[1] = new int[]{1,65,0,10,3}; data[2] = new int[]{34,5,6,67,3,54}; //get the biggest arrays length int maxArrayLength = 0; for(int i=1; i&lt;data.length; i++) { if(data[i].length &gt; data[maxArrayLength].length) maxArrayLength = i; } maxArrayLength = data[maxArrayLength].length; //collect the max in each category int [] categoryMax = new int[maxArrayLength]; //loop through the categories for(int i=0; i&lt;maxArrayLength; i++) { //in each iteration we get a winner int categoryWinner = 0; // now loop through the values of the current category for(int j=0; j&lt;data.length; j++) { int [] actualArray = data[j]; int [] winnerArray = data[categoryWinner]; //check if we are in the bounds, if so, then perform a simple maxsearch if(i&lt;actualArray.length) if(actualArray[i] &gt; winnerArray[i]) categoryWinner = j; } //set the current element of the winners array. categoryMax [i] = data[categoryWinner][i]; } int sum = 0; // we are ready, print it out! for(int i=0; i&lt;categoryMax.length; i++) { System.out.println((i+1) + ". groups winner: " + categoryMax[i]); sum+=categoryMax[i]; } System.out.println(sum); </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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