mercredi 1 novembre 2017

Using Random class to continue adding a random digit to a given number in Java

Given an integer, 234, how would I use a Random object to take this number and add only one random digit to it without making it a String. So the goal in this case would be to return a number that has 4 digits, with the last one being random. So for example the next number could be 2347. Then I want to take this number and do the same thing for 5 digits, for instance 23471. I know I can multiply by 10 to increase the digit count by 1, but this would not be random. The only methods I'm aware of for the Random class are nextInt(int n) and nextDouble().

Random generator = new Random();
int gameNum = 234;
public static int UpdateGameNum(int gameNum, Random)
{




Aucun commentaire:

Enregistrer un commentaire