-2

When I enter the code I get an output like [I@190d11. How can I solve it?

public static void main(String[] args) 
{
    int N;
    N = 10; 
    System.out.println(getRandom(N));           
}

public static int[] getRandom(int N)
{
    int i, j, x, y;
    Random generator = new Random();
    int[] random = new int[N * 2];
    x = (2 * N) - 1;
    y = -N;
    for(i = y; i <= N; i++)
    {
        for(j = 0; j < N - 1; j++)
        random[j] = generator.nextInt(x - y - 1) + y;
    }
    return random;
}

I think it is related with static but I couldn't solve it.

Blue_Alien
  • 2,148
  • 2
  • 25
  • 29
harold_finch
  • 80
  • 3
  • 11

1 Answers1

2

You are printing array , whose default to String pringts objectName and hashCode. If you want to print all the values in array use :-

System.out.println(Arrays.toString(getRandom(N)));   

Or iterate over the array and print each element separatly

Panther
  • 3,312
  • 9
  • 27
  • 50
  • that will work thanks – harold_finch Dec 15 '14 at 15:39
  • welcome, your question is actually duplicate but only reason i answered it, cause you were not able to figure out you were fetching array from method. So, it is possible to miss such detail. Could you except this answer by clickin a tick in side of answer. – Panther Dec 15 '14 at 15:42