Array of the 3 largest numbers
<p>I was working on a method trying to create a array that will contain the 3 largest numbers. But there is an error in my code and I couldn't understand what I did wrong. Thanks!</p>

<p>public class Method3 {</p>

<pre><code>public static void main(String[] args) {
    int[] a={2,5,6,7,9,1,2,3,5,9,7};

    System.out.print(largestSum(a));


}


public static int[] largestSum(int[] a){

    int temp, first, second, third;
    first=second=third=a[0];

    for(int element: a){

        if(first &lt; element)
            {
                temp=first;
                first=element;
                second=temp;
            }

        if(second&lt;element &amp;&amp; first&gt; element)
            {

                temp=element;
                second=element;
                third=temp;
            }

        if(third&lt; element &amp;&amp; second&gt; element)
            {
            temp=element;
            third=element;

            }

    }

    int [] array=new int[3];
    array[0]=first;
    array[1]=second;
    array[3]=third;



    return array;
}
</code></pre>

<p>}</p>
