Function that inverts vector values into another vector

-1

I have the following code:

import java.util.Scanner;

            public class ativ15 {

                public static void main (String[] args) {

                Scanner sc = new Scanner (System.in);

                int i;
                int A[] = new int [10];
                int B[] = new int [A.length];

                System.out.println ("Digite os elementos do vetor: ");

                for (i=0; i<10; i++){               
                A[i] = sc.nextInt();
            }

                GeraInverso (A, B);

        }

                static void GeraInverso (int A[], int B[]) {

                int i, temp;

                for (i=0; i<A.length; i++){
                B[i] = A[i];
            }

                for (i=0; i<10; i++) {

                if (i<5) {
                temp = B[i];
                B[i] = B[10-i-1];
                B[10-i-1] = temp;
                }
            }                                           

       }

}

I need the main function to print the value of vector B (the Inverse function inverts the values of vector A and copies to vector B). For this, what does the GeraInverso function return? How should I proceed?

    
asked by anonymous 09.11.2016 / 02:47

1 answer

1

No need to return anything. Vectors in Java are passed by reference, so changes occurring in GeraInverso are reflected in main .

    
09.11.2016 / 02:59