Jaime Esono
Jaime Esono

Reputation: 17

random string of numbers

I want to print a string of numbers, but I get the followyng: [I@7c230be4

This is my code:

import java.util.Random;

class Aleatorio {
    public static void main(String[] args) {
        Random diceRoller = new Random();
        int cifra[]= new int[5];
        for (int i = 0; i < cifra.length; i++) {
            int roll = diceRoller.nextInt(9)+1 ;
            cifra[i]=roll;
        }
        System.out.println(cifra);
    }
}

Upvotes: 0

Views: 86

Answers (2)

vhunsicker
vhunsicker

Reputation: 539

Try this

for (int c : cifra) {
  System.out.println(c);
}

instead of this

System.out.println(cifra);

Upvotes: 1

Reimeus
Reimeus

Reputation: 159754

You are seeing the Object#toString representation of the int array Object. To display its contents, you could use:

Arrays.toString(cifra)

Upvotes: 4

Related Questions