This site requires JavaScript, please enable it in your browser!
Greenfoot back
Sammyy2323
Sammyy2323 wrote ...

2020/6/5

Making a variable that takes all the numbers from an array

Sammyy2323 Sammyy2323

2020/6/5

#
I want to make something that will make all of the numbers that the int array outputs and make it into a variable that i can pass to a different world.
int [] num = new int [4];
        num [0] = 5+Greenfoot.getRandomNumber(2);
        num [1] = 5+Greenfoot.getRandomNumber(2);
        num [2] = 5+Greenfoot.getRandomNumber(2);
        num [3] = 5+Greenfoot.getRandomNumber(2);
        
        for (int i=0; i<num.length; i++)
        
        {
            
            for (int n=0; n<num[i]; n++)
            {
                
                int randomX = Greenfoot.getRandomNumber(getWidth()-50)+25;
                int randomY = Greenfoot.getRandomNumber(getHeight()-50)+25;
                Ball0 ball = new Ball0(i);
                addObject(ball, randomX,randomY);
                
            }
            
        }
    }
Sammyy2323 Sammyy2323

2020/6/5

#
i want num, num1,num2,num 3 to be added into a variable and then I pass it to a different method
danpost danpost

2020/6/5

#
Sammyy2323 wrote...
i want num, num1,num2,num 3 to be added into a variable and then I pass it to a different method
Why can't you just pass the array?
You need to login to post a reply.