jeudi 26 novembre 2015

how to excluding number in random number (java)

So i will get a random number between 1 to 9999

but i want to excluding 1111 ,3333,4444,7777 and is that use while loop?

Random r = new Random();

int x = r.nextInt(9999);

while (x == 1111 || x==3333) 
  {
x = r.nextInt(9999) + 1;
  } 




Aucun commentaire:

Enregistrer un commentaire