0

I am simply trying to create an array of ten numbers between 0 and 12. My program is giving me "[I@e8bb762" as output. Please help. This is my program.

public class Array {
  public static void main (String [] args){

    //variable
    int [] row = new int [12];

    for(int i= 0; i < 12; i++){
      row [i] = (int)(Math.random() * 12);
    }



    System.out.println(row);
  }
}
1
  • Change the way your are printing it to System.out.println(Arrays.toString(row)) Commented Nov 20, 2013 at 0:40

2 Answers 2

2

Arrays are objects in Java that don't override Object's toString() method, which is responsible for the output you see.

Use the Arrays.toString method, suited for converting arrays to strings.

System.out.println(Arrays.toString(row));
Sign up to request clarification or add additional context in comments.

Comments

0

You could also simply print each number in your array within the same loop you already have right after the number is generated. In your loop add the line:

System.out.print(row[i] + ","); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.