public class ordenarVetor {
public static void main(String[] args) {
int a[] = {9,4,6,3,1,0,8};
int aux;
//ordenar
for (int x = 0; x < a.length; x++) {
for (int y = x+1; y < a.length; y++) {
if(a[x] < a[y] ){
aux = a[x];
a[x] = a[y];
a[y] = aux;
}
}
}
System.out.print("[");
for (int i = 0; i < a.length; i++) {
System.out.print("-");
System.out.print(a[i]);
}
System.out.println("-]");
}
}
quinta-feira, 14 de junho de 2012
Ordenar vetor em java
Para ordenar um array decrescente podemos utilizar a seguinte solução:
Assinar:
Postar comentários (Atom)
valeu vinicios tenha esquecido graticie perfeito.
ResponderExcluirVlw mano!
ResponderExcluirExcelente!