Search:

Type: Posts; User: Norm

Search: Search took 0.18 seconds.

  1. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Hopefully arrays will be easier next time.
  2. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Write a loop like you had before that prints the index value and the contents of the array at that index.


    That is easily verified by looking at the numbers that were printed on the line above...
  3. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Ok, that looks about right.
    For testing to see what is in the array use the Arrays class's toString() method:
    System.out.println("an ID "+ java.util.Arrays.toString(theArrayNameHere));
  4. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Why does the code use the value 0 for the index into the array?
    I said:
    " uses the random number as an index to the counts array "
  5. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    now add ONE line of code that uses the random number as an index to the counts array to access one of its elemens.
    Increment that element by one.
  6. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Can you do this a few steps at a time. There is a lot of code in you post that don't make sense.
    Start with these first steps:
    1) define an array with 10 slots to hold the counts
    2) define a loop...
  7. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Ok, that is what I thought. There are supposed to be 100 randomly chosen values in the range 0 to 9.
    Did you rewrite the code?
  8. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    I meant there to be a single loop for counting the random numbers.

    There could be another loop to print out the results AFTER the counting was done.

    The code defines an array to hold the counts...
  9. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Get rid of that code and start over.
    Make a loop that goes around 100 times: "generate random 100 numbers"
    inside that loop generate a random number: "from 0 to 9"
    Use that random number to index...
  10. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Treat the element of an int array as an int variable:


    int[] intArray = new int[10]; // define an array
    int intVar = 0; // define a variable


    intArray[idx]++; // increments the value...
  11. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Use the random number as the index into the array. Increment the indexed element by 1 to count the random number.
  12. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    If the value of numbers doesn't change then the same number is assigned to all the elements.
    Say numbers is assigned a 7, then all the array elements will be assigned a value of 7.

    The...
  13. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    If you want random numbers assigned to the array, you need to use the Random class to create each number that is assigned to an element of the array. Like is assigned to the variable: numbers

    ...
  14. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Instead of the numbers: 0,1,2 as the index, use the for loop control variable as the index.
  15. Replies
    30
    Views
    2,219

    [SOLVED] Re: Counting and Math.random

    Where does the code assign any values to the elements in the digitArray array?
    There needs to be a loop that indexes through the elements of the array and assigns a number to each element.
Results 1 to 15 of 15