I need to store the same data in a stack and in a vector.

0

When I send print the vector says: "[I @ 1540e19d" Urgent help please! : (

public static void main(String[] args) {
    Scanner sc = new Scanner (System.in);
    int n,x,dato,cp=0,cn=0,guardaDato;
    System.out.println("=======================================");
    System.out.println("Introduzcase el tamaño de la pila 1: ");
    n=Keyboard.readInt();
    System.out.println("=======================================");
    System.out.println("El tamaño de la pila 1 es de "+n+" elementos.");
    System.out.println("=======================================");

    PilaG<Integer> pila1 = new PilaG<Integer>(n);
    int []vector= new int [n];

    for ( int i=0; i<n;i++)
    {
        System.out.println("Introduce el numero en la posición "+(i+1));
        dato= sc.nextInt();
        pila1.Push(dato);
    }

    pila1.estado();

    for(int k=0;k<n;k++)
    {
            pila1.Pop();
            guardaDato=(int) pila1.dret;
            vector[k]=guardaDato;
    }

    System.out.print(vector);


}

}

    
asked by Bryan Vazquez 28.02.2018 в 01:02
source

3 answers

0

You are trying to print vector in an incorrect way. Change the last line to:

System.out.print(Arrays.toString(vector));
    
answered by 28.02.2018 / 03:16
source
0

You can print the vector using a loop

   for (int index=0;index<vector.length;index++)
        {
            System.out.println(vector[index]);
        }
    
answered by 28.02.2018 в 01:12
0

You can print the vector using a loop To print the contents of a collection you must go through each position of this. What is coming out of the console is basically the memory address of the variable, in this case the vector. if you want to print or do any operation with the data you can use a traditional for or if it was a collection as in this case they are whole you can make a system.out.println () of the vector.

eg Traditional For:

    int[] vector = {2,3,4,5,6};

    for (int index=0 ; index < vector.length ; index++){
        System.out.println(vector[index]);
    }

Output

ex: collection

    List<Integer> vector = new ArrayList<>();
    vector.add(2);
    vector.add(3);
    vector.add(4);

    System.out.print(vector);

Output:

Depending on what you are going to want to use your collection for, it will be better to use one or the other.

    
answered by 28.02.2018 в 15:46