Adding ints to an array in Java -


i trying create random number add array (arr). have looked around answers seem not working or outdated. here have tried:

int[] arr = {}; int rand =  (int) math.round(math.random() * 100); arr = append(arr, rand); 

however, doesn't seem work there red line under append saying "the method append(int[], int) undefined type new actionlistener(){}". highly appreciated!

you first declare array so:

int[] arr;

do know how many integers storing?

arr = new int[10];

you use loop go through each element in array.

for (i=0; i<10; i++) {   int rand = (int) math.round(math.random() * 100);   arr[i] = rand; } 

from arrays (java docs)

hope helps.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -