Results 1 to 4 of 4
  1. #1
    s_mxyzptlk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Fill Array with Numbers from Random generator [HELP]

    Im using 2020 as my seed value... I need to fill the array with 123 real numbers in the range of 0.0 and 999.0

    import java.util.*;
    public class Bubble {

    public static void main(String[] args) {
    Random generator = new Random(2020);
    for (int idx = 1; idx <= 123; ++idx){
    double d = generator.nextDouble()* 999.0;
    }
    double [] A= new double[123];



    }

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Fill Array with Numbers from Random generator [HELP]

    I need to fill the array
    You need to assign values to the slots in the array if you want to fill it. Your posted code doesn't assign any values to any array.

    Set the tutorial about arrays: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

  3. #3
    s_mxyzptlk is offline Member
    Join Date
    Mar 2012
    Posts
    4
    Rep Power
    0

    Default Re: Fill Array with Numbers from Random generator [HELP]

    Thats what im having trouble with... I wanna add 123 numbers to the array ... This is my revised code and it wnt compile and run.

    import java.util.*;
    public class Bubble {

    public static void main(String[] args) {
    Random generator = new Random(2020);
    for (int i = 1; i <= 123; ++i){
    int d = generator.nextInt()* 999;
    }
    int [] A= new int[123];

    for (int n=0; n<A.length; n++);
    {
    System.out.println(d);
    }


    }

    }

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Fill Array with Numbers from Random generator [HELP]

    I wanna add 123 numbers to the array
    To put numbers into the array you need to use an assignment statement that points to each slot.
    theArray[index] = value; // assign value to the slot at index in theArray

Similar Threads

  1. I need help generating random numbers for a fill array
    By william979 in forum New To Java
    Replies: 15
    Last Post: 05-04-2011, 12:57 AM
  2. Array of random numbers ...
    By shane1987 in forum New To Java
    Replies: 31
    Last Post: 11-14-2010, 09:33 PM
  3. Replies: 6
    Last Post: 10-03-2010, 08:25 AM
  4. Store Random numbers into Array
    By abby0910 in forum New To Java
    Replies: 19
    Last Post: 07-12-2010, 12:59 AM
  5. Random Numbers generator
    By pinkdreammsss in forum Java Applets
    Replies: 10
    Last Post: 04-08-2010, 03:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •