Skip to content

Instantly share code, notes, and snippets.

@rafaduka
Created September 12, 2018 07:10
Show Gist options
  • Save rafaduka/1073742080e3ece416aea66d87ad20f6 to your computer and use it in GitHub Desktop.
Save rafaduka/1073742080e3ece416aea66d87ad20f6 to your computer and use it in GitHub Desktop.
public static void main(String args[]){
int[] vet = {8, 9, 3, 5, 1};
int aux = 0;
int i = 0;
System.out.println("Vetor desordenado: ");
for(i = 0; i<5; i++){
System.out.println(" "+vet[i]);
}
System.out.println(" ");
for(i = 0; i<5; i++){
for(int j = 0; j<4; j++){
if(vet[j] > vet[j + 1]){
aux = vet[j];
vet[j] = vet[j+1];
vet[j+1] = aux;
}
}
}
System.out.println("Vetor organizado:");
for(i = 0; i<5; i++){
System.out.println(" "+vet[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment