Considere o código JavaScript a seguir:
<html>
<body>
<script>
var vet = [2, 10, 3, 56, 34, 21];
var i,j,aux;
for(i = 1; i < vet.length; i++){
aux = vet[i];
for(j = i-1; (j >= 0) && (aux < vet[j]); j--)
vet[j + 1] = vet[j];
vet[j + 1] = aux;
}
document.write(vet);
</script>
</body>
</html>
Quando a página for executada no navegador será exibido na tela:
<html>
<body>
<script>
var vet = [2, 10, 3, 56, 34, 21];
var i,j,aux;
for(i = 1; i < vet.length; i++){
aux = vet[i];
for(j = i-1; (j >= 0) && (aux < vet[j]); j--)
vet[j + 1] = vet[j];
vet[j + 1] = aux;
}
document.write(vet);
</script>
</body>
</html>
Quando a página for executada no navegador será exibido na tela:
- A)56,34,21,10,3,2
- B)ArrayIndexOfBoundsException
- C)2,10,34,56,21,3
- D)2,3,10,21,34,56
- E)um espaço em branco, pois o comando document.write está incorreto.