static void Inverte_Vet (int n, int v[])
{
int aux;
for(int i = 0; i < n/2; i++) {
for(int j = (n-1); j > n/2; i--)
{
aux = v[i];
v[i] = v[j];
v[j] = aux;
}
}
}
Não sei como faço…
O erro:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
at L05_Q09_Mod_Inverte_Vetor.Inverte_Vet(L05_Q09_Mod_Inverte_Vetor.java:10)
at L05_Q09_Mod_Inverte_Vetor.main(L05_Q09_Mod_Inverte_Vetor.java:29)
Java Result: 1
public class L05_Q09_Mod_Inverte_Vetor
{
static void Inverte_Vet (int tam, int v[])
{
int aux;
for (int i = 0 ; i<tam ; i++)
{
aux = v[tam];
v[tam] = v[i];
v[i] = aux;
tam--;
}
}
}