Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Storing random numbers into a String field

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Storing random numbers into a String field

    Hello
    I need help on storing random generatored numbers into a string every time they get generated , im also to store the string i want , but not the amout of numbers that i select to be generated. I am using a for loop to do it, i was wondering how can i do it ?
    public void generatorRandom(String o , int p)
    {
    int number;
    Random l = new Random ();
    for (int k=0; k<p; k++)

    {
    number = l.nextInt(10);


    customerID = o + number;


    }

    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,137
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: Storing random numbers into a String field

    help on storing random generatored numbers into a string every time they get generated
    Can you explain in more detail?
    What range of values do you want the random number to have?
    How many digits do you want in the String?

    What happens when the posted code is compiled and executed?

    Do you know how to concatenate a value onto an existing String?
    theString += theValue;
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    67
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Storing random numbers into a String field

    well the range is just between 0-9 , it depends on the parameter how many go into the string.
    The code only stores what string is in the parameter n the first generated number

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,137
    Thanks
    48
    Thanked 2,156 Times in 2,129 Posts

    Default Re: Storing random numbers into a String field

    Did you read all my post? The part about concatenation?

    BTW o & p are poor variable names. Name should describe what the variables contain.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Adding 100 single digit numbers to a Text Field
    By CodyReuille in forum Java Theory & Questions
    Replies: 2
    Last Post: July 3rd, 2012, 03:58 PM
  2. Can't get seven random numbers, only one.
    By alpvii in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 6th, 2010, 04:39 PM
  3. help w/ storing/scanning numbers in two dimensional arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 10
    Last Post: December 1st, 2010, 10:56 PM
  4. help w/ storing/scanning numbers in arrays
    By robertsbd in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 17th, 2010, 09:55 PM
  5. Random numbers
    By Pooja Deshpande in forum Java SE APIs
    Replies: 8
    Last Post: June 5th, 2009, 04:36 AM