Results 1 to 4 of 4
Thread: Problem printing an array
- 11-01-2009, 09:16 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
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.
-
Either use the Arrays utility class:
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.Java Code:System.out.println(java.util.Arrays.toString(tableauInt));
- 11-01-2009, 09:56 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
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.
-
You're welcome, and again, welcome to the forum!
Similar Threads
-
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
Printing the contents of an array of objects
By Mr.Paplu in forum New To JavaReplies: 1Last Post: 03-19-2009, 04:49 PM -
Printing Array elements
By new person in forum New To JavaReplies: 2Last Post: 02-23-2009, 08:57 PM -
printing array
By mayhewj7 in forum New To JavaReplies: 6Last Post: 02-12-2009, 02:01 PM -
Printing Byte Array
By suchismitasuchi in forum New To JavaReplies: 3Last Post: 01-19-2009, 10:58 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks