简体   繁体   中英

Queueing 1d arrays - Java - Queue - 2D array

Want to implement a Queue of 1D arrays, and should convert the queue into a 2D matrix without utilizing more additional memory.

Actually, I want to implement this in android How shall I do?

import java.util.*;
class test{
    public static void main(String aActuallya[]){
        Queue<int[]> data = new LinkedList<int[]>();
        int[] arr = new int[3];
        Scanner scan = new Scanner(System.in);
        for(int j=0;j<3;j++)
        {
            for (int i=0;i<3;i++)
                arr[i]=scan.nextInt();
            data.add(arr);
        }
        System.out.println(data.toArray());
    }
}

My input:

1 2 3
4 5 6
7 8 9

output:

[Ljava.lang.Object;@74a14482

As user202729 mentioned in the comment above, what your actual problem is is that you are not printing out the array properly but instead are printing the memory address.

To print it you will have to loop through the entire array. For example:

int[] dataArray = data.toArray();
for(int i=0; i<dataArray.length; i++){
    System.out.print(dataArray[i]);
}

From there you can go ahead and debug your implementation if need be.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM