Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a random 4 digit number, and storing it to a string [duplicate]

Tags:

java

android

I'm trying to create a method which generates a 4 digit integer and stores it in a string. The 4 digit integer must lie between 1000 and below 10000. Then the value must be stored to PINString. Heres what I have so far. I get the error Cannot invoke toString(String) on the primitive type int. How can I fix it?

   public void generatePIN() 
   {

        //generate a 4 digit integer 1000 <10000
        int randomPIN = (int)(Math.random()*9000)+1000;

        //Store integer in a string
        randomPIN.toString(PINString);

    }
like image 344
user3247335 Avatar asked Mar 06 '14 23:03

user3247335


1 Answers

You want to use PINString = String.valueOf(randomPIN);

like image 105
mikejonesguy Avatar answered Oct 10 '22 03:10

mikejonesguy