0
I need to know how to change this logic to receive vectors of any size.
public void inverter(int[] vetor) {
int i;
int temp;
for(i=0; i < 3; i++){
temp = vetor[i];
vetor[i] = vetor[8-i];
vetor[8-i] = temp;
}
}
Ex: int[] vector 1 = new int[]{1,2,3,4,5,6,7,8,9};
//Prints [9,8,7,6,5,4,3,2,1]
Dude I’m new here and I don’t understand much how it works. What should I do to get this help I posted. Thanks
– SnSilva
When a question is marked as duplicate, it is because it already has an answer. You accessed the links I indicated in the other question?
– user28595
enters the Stackoverflow goal in Portuguese it has all the rules, usually in the beginning personal and very rude , more accustomed
– Marcelo Batista
@Marcelobatista who was rude here? Closes without saying anything complain, closes and a touch the author, is rude, it is too difficult to please here.
– user28595
I didn’t talk about Oce, in general this is the perception with any weaker question say
– Marcelo Batista
Personal calm rsrs
– SnSilva
This solves the problem https://answall.com/a/64830/3635 ?
– Guilherme Nascimento
@Guilhermenascimento even helps, but I need it to be a void method with no return.
– SnSilva
@Snsilva gives a look https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-ask-questions
– Marcelo Batista
Thanks @Marcelobatista I’ll take a look.
– SnSilva
But why does it have to be
voidor not? After all it is only a method that you will add to your class for a specific and unique use, I see no sense or need for this to be void, after all you can create more than one method, as many as you want and each for a need ;)– Guilherme Nascimento
It is an activity that the teacher has passed in repl.it and the method that is there is void and I can’t change it, I just have to make logica within that method @Guilhermenascimento.
– SnSilva
@Snsilva wants no return, instead of
return, display withSystem.out.prinln. What matters in the answer there is not the return, is you understand how it was done and reproduce as your exercise asks.– user28595
Got it here @Articuno, thanks.
– SnSilva
Dear I did here and it worked, but I would have to reverse the vector itself without having to create another?
– SnSilva
Snsilva made an example: https://repl.it/@inphinit/snsilvajava - it works like this, it clones the object (it is necessary to do this because of the reference of the object, so there is no setting
vetor[i] = vetor[8]without affecting the original array causing the values to conflict. The other example without copying/cloning array and using native methods is this: https://repl.it/@inphinit/snsilvajava - cc @Articuno– Guilherme Nascimento
You can do it without having to create a new one, your question logic is right, just abstract the size of the array, see: https://ideone.com/bxYEt8 c/c @Guilhermenascimento
– user28595
@Sensational trick! D
– Guilherme Nascimento
@Articuno this was exactly what I needed, thank you very much. How do I vote on this solution as resolved?
– SnSilva
@Guilhermenascimento was worth the service, was nice example in repl.it.
– SnSilva