开发者

J2ME - Storing ints in an array or similar

开发者 https://www.devze.com 2023-03-17 16:34 出处:网络
I am currently writing an app for a card game in j2me, I have used random number generator to create 5 random ints that will be stored in an array or similar to represent the players hand of cards (as

I am currently writing an app for a card game in j2me, I have used random number generator to create 5 random ints that will be stored in an array or similar to represent the players hand of cards (as each number represents a corresponding card in the pack)

At the moment, the following card creates the random numbers

int n = 0;

Random r = new Random();

while(n<5) {

int i = r.nextInt(52);

System.out.println( i);  

n++;

I have tried to use a vector to store the 5 i values but I could not get this working, I was hoping for any suggestions of what I should consider using for storing i which will be accessibl开发者_高级运维e during gameplay.

Thanks Guys! :-) x


I dont see why you cant use Vector to store the values.

try this..

   int n = 0;

   **Vector<int> name = new Vector<int>();**

   Random r = new Random();

   while(n<5) {

   int i = r.nextInt(52);

   System.out.println( i);  
   **name.set(i, n);**

   n++;
}

if this code was in a method, you can pass in the vector as a reference, so you can store the values.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号