How to go through an array and add certain values?
<p>I'll try to explain it better.</p>

<p>So k = 2.
In[]profits = new {1, 2, 3, 1, 6, 10}</p>

<p>For the first part it should be:</p>

<p>1,2,3</p>

<p>Then look for the least value in {1,2,3} which is 1. Then add that to the next value which is 1. So it would be 1+1. The outcome would be {2,3,2}. Again look for the least value which is 2 and add it to the next value 6. So it would be 2+6. The outcome would be {3, 2, 8}. Finally, for the least value in {3,2,8} and add it to the next value 10. So it would be and 10+2. The outcome is {2, 8, 10}. Then look for the least value in that which is 2. </p>

<p>If you guys could at least guide me on how to do this?</p>

<p>This is the tester:</p>

<pre><code>import java.util.Arrays ;

 /**
 Presents some problems to the BillBoard class.
 */

public class BillboardTester {

    public static void main(String[] args) {
    int[] profits = new int[]{1, 2, 3, 1, 6, 10} ;

        int k = 2 ;

        System.out.println("Profits: " + Arrays.toString(profits) + "   k = " + k)  ;

        Billboard bb = new Billboard(profits, k) ;
        System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
        System.out.println(bb) ;

        k = 3 ;
        profits = new int[]{7, 4, 5, 6, 1, 7, 8, 9, 2, 5} ;
        System.out.println("Profits: " + Arrays.toString(profits) + "   k = " + k)  ;
        bb = new Billboard(profits, k) ;
        System.out.println("Maximum Profit = " + bb.maximumProfit()) ;
        System.out.println(bb) ;
    }
}
</code></pre>

<p>This is what I have so far for the class: </p>

<pre><code>public class Billboard {
    private int maximumprofit; // The max profit 
    private int finalcost; // The final cost of removing the billboards

    public Billboard(int[]profits, int k) {
        for (int i = 0; i &lt; profits.length; i++) {
            maximumprofit+= profits[i];
        }
    }

    public int maximumProfit() {
        return maximumprofit;
    }
}
</code></pre>
