mercredi 9 février 2022

the arraylist return a [ ] [closed]

I wrote this code which should return random numbers from 0 to n in ArrayList but when I run it, it just prints [], so how I can fix that.

public ArrayList<Integer> randomSeed(int n)
    {
        ArrayList<Integer> a = new ArrayList<Integer>();

        for(int i=0; i<a.size(); i++)
        {
            int x = a.get(i);
            x = rand.nextInt(n);
            System.out.print(x+ ((i+1)%10==0 ? "\n" : " "));
        }
        
        return a;
    }



Aucun commentaire:

Enregistrer un commentaire