Whole integer random, filling an array does not only produce integers
source link: https://www.codesd.com/item/whole-integer-random-filling-an-array-does-not-only-produce-integers.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Whole integer random, filling an array does not only produce integers
I have code to fill an array with 10 integers but for some reason it is not only filling it with integers. EX. [I@5483cd or [I@1690726 Anyone know why?
public static void main(String[] args) {
int[] array = new int[10];
int length = array.length;
for (int i = 0; i < length; i++) {
array[i] = (int)(Math.random () * 10);
}
System.out.println(array);
}
System.out.println(array)
is printing the hashcode for the array, not the values inside the array. Iterate over the values in the array and print those, like this:
for (int val : array)
{
System.out.println(val);
}
Even simpler, use: Arrays.toString(array)
. See What's the simplest way to print a Java array?
Related Articles
& ldquo; git --bare init & rdquo; does not only produce a .git directory
A random image generator that does not repeat the xcode code
Conflict of names? 'System.Array' does not contain a definition for 'item'
array does not decompose into a pointer if it is passed by the const reference in a model function
Push array if the array does not exist in the array of arrays
System.Array does not contain a definition for 'Any' - C #
returns an array that contains only odd integers
Java multidimensional array does not fill correctly
Sorting a multidimensional array does not work with decimals
The program that removes duplicate entries from an array does not remove some entries
Array does not reset the function and removes elements from the alternate array
PHP foreach with multidimensional array does not print all values
Dynamic 3D Array does not work on my class (will it use better vectors?)
ActionScript 3 Reference to public static var in array does not work
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK