2

Whole integer random, filling an array does not only produce integers

 3 years ago
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

advertisements

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

This is confusing. I've read in many places that git --bare init sets up the directory you're running the command from as a bare Git repository, the kind you want to use as a central repository. In particular, I read where this command produces simpl

A random image generator that does not repeat the xcode code

How would I create a random image generator that does not repeat images until it has been through them all once? for example: -(IBAction)randomimagebutton { int randomimages = rand() % 5; switch (randomimages) { case 0: imageview.image = [UIImage ima

Conflict of names? 'System.Array' does not contain a definition for 'item'

I am using a webservice (provided by webservices.nl) to extract company data depending on a company number. myserviceBusiness = new nl.webservices.ws1.Webservicesnl(); nl.webservices.ws1.BusinessDossierV3PagedResult result = null; result = myserviceB

array does not decompose into a pointer if it is passed by the const reference in a model function

This question comes from this one: c++ pass array to function question but since the OP accepted an answer I guess nobody will read it now. I tried this code on g++. It seems that the array does not decay to a pointer when passed to this function (th

Push array if the array does not exist in the array of arrays

I am currently working on a small home project, and I am trying to push an array into an array of arrays, if said array does not already exist in the array of arrays. var arrayArr = [[1,4]]; function pushArr() { var tempArr = [1, 3]; var tempArr2 = [

System.Array does not contain a definition for 'Any' - C #

Using Visual Basic // C# I'm trying to search through my stored arrays for a match to the user input. For example, the user has stored the data for a USB, and now wishes to bring that information back up. FULL CODE BELOW I'm already using IndexOf to

returns an array that contains only odd integers

Ok, so I have this problem where when given an Array arr, return an Array which contains only odd integers in the original order from arr. My code: public int [] youMakeMeOdd(int [] arr) { int[] odds; odds = new int[arr.length]; for(int i = 0; i < ar

Java multidimensional array does not fill correctly

I have declared a multi- dimensional array like this: String[][] contentDetails = {}; I populated the array like this: contentDetails[][] = {{"Availability","Available from: "+empst}, {"Rate in EUR/Hour",rst.getString(25)}};

Sorting a multidimensional array does not work with decimals

This question is related to, and based off the script from, this question: How does one sort a multi dimensional array by multiple columns in JavaScript?. My solution worked at the time (or so I believe), but after making a series of changes to our c

The program that removes duplicate entries from an array does not remove some entries

I've written the following short program that prompts a user to construct an ArrayList of integers and then displays that same array with duplicates removed. The program works just fine with simple numbers, such as 1, 10, or even 100. Please note tha

Array does not reset the function and removes elements from the alternate array

In this word game i generate 9 letters randomly wait for users input then check if for each letter of the users input "value" they use only the letters generated at the start for example if the startwordgame() generated the word maximizes the us

PHP foreach with multidimensional array does not print all values

I have a very simple multidimensional array and some PHP code. The code should print the p_id values, but it does not do it. Do I really have to add one foreach more or is there other ways? And here is the array: Array ( [2764] => Array ( [status] =>

Dynamic 3D Array does not work on my class (will it use better vectors?)

I have created a class that works for a static array, but when I try to use it with my dynamic array, it is not working. (To not fill this page with a long long code, I just copied one function of my class) I think that my dynamic array is not proper

ActionScript 3 Reference to public static var in array does not work

I'm setting up a class of public static vars that are to be BitmapData. The problem I'm having is I can't seem to reference the vars dynamically in an array, making it impossible to give them values without some serious procdedural style coding. This

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK