Results 1 to 4 of 4
  1. #1
    denial is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default Problem printing an array

    Hi people, I'm having little problem printing the resulting array in this simple program. Someone told me that the answer it was producing is the adress of the array and not the array itself, but i dont know how to get it right and print the array.

    Here's the program.

    Thanks.

    public class TableauTest {

    public static void main(String args[]){

    int tableauInt[] = new int [10];

    for (int i = 0; i < 10; i++){

    double random = Math.random();

    int partieEntiere = (int) (random * 20);

    System.out.println(partieEntiere);

    tableauInt[i] = partieEntiere;

    }

    System.out.println(tableauInt);

    }

    }

    The goal is to put numbers from 0 to 20 in an array of 10.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Either use the Arrays utility class:
    Java Code:
    System.out.println(java.util.Arrays.toString(tableauInt));
    or use a for loop to iterate through the array printing each item in the array. Also, please use code tags when posting code (please see my signature), and finally, welcome.

  3. #3
    denial is offline Member
    Join Date
    Nov 2009
    Posts
    2
    Rep Power
    0

    Default

    Thanks Fubarable! I totally forgot the toString method :$. A brand new brain could have saved me few hours of web searching heheh. About the code format, I saw the way to do it on another post after I posted mine, so I'll do this new time. thanks again.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  2. Printing the contents of an array of objects
    By Mr.Paplu in forum New To Java
    Replies: 1
    Last Post: 03-19-2009, 04:49 PM
  3. Printing Array elements
    By new person in forum New To Java
    Replies: 2
    Last Post: 02-23-2009, 08:57 PM
  4. printing array
    By mayhewj7 in forum New To Java
    Replies: 6
    Last Post: 02-12-2009, 02:01 PM
  5. Printing Byte Array
    By suchismitasuchi in forum New To Java
    Replies: 3
    Last Post: 01-19-2009, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •