The simplest idea that comes to mind is to sort the array. You should use any sort algorithm after filling your array.
Example using "buble sort":
for (int i = 0; i < tabela.length-1; i++)
for (int j = 0; j < tabela.length-i-1; j++)
if (tabela[j] > tabela[j+1])
{
int temp = tabela[j];
tabela[j] = tabela[j+1];
tabela[j+1] = temp;
}
Here you can find an explanation of the algorithms and their examples.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…