mardi 5 mai 2020

Trying to print 1 - 9 using Math.Random() or Random() but it's not working [duplicate]

I have to print random numbers from 1 - 9. It prints up to 9 but it keeps printing 0 even though I don't want 0.

I've played around with numbers but the 0 just won't go away.

int num = (int)(Math.random() * 10);

or

Random randNo = new Random()

.. my code ..

int num = randNo.nextInt(9) + 1;



Aucun commentaire:

Enregistrer un commentaire