Results 1 to 7 of 7
  1. #1
    caro is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Smile Random numbers and arrays

    Hi,
    I'm new to writing java and am having a bit of trouble writing a program and would really appreciate some help :)
    Im trying to make a program that creates an array of 20 random integers between 0 and 99, then allows the user to enter a number (N) between 0 and 99 so that it (the program) can tell the user how many of the integers are greater than or equal to N.
    Everything i've tried gets an error! please help! :o

  2. #2
    sayan751 is offline Member
    Join Date
    Feb 2009
    Posts
    29
    Rep Power
    0

    Default

    you can post your code, it will be helpfull otherwise check this example:Generate random numbers using Math.random | Java Examples - Java Program Sample Source Code
    Impossible is Nothing

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    ... moving to "New to Java" subforum since no reference to NetBeans can be observed.

    CJSL

    Edit: Moved from the "NetBeans" subforum
    Last edited by CJSLMAN; 06-09-2009 at 08:21 PM. Reason: Updated to indicate that the post was moved
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default pseudo code

    Here's some pseudo code that might help:

    • create array (size 20)
    • Ask user for number between 0 & 99
    • start loop (20 loops)
    • create random number between 0 & 99 (Using Random class)
    • insert random number as an element into the array
    • end loop
    • start loop (size 20)
    • if array element >= user's number then add 1 to "greaterEqual" variable
    • end loop
    • print "greaterEqual" variable
    ... or somethng like that

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  5. #5
    Mr.Beans's Avatar
    Mr.Beans is offline Senior Member
    Join Date
    Apr 2009
    Location
    Virginia Beach, Virginia
    Posts
    149
    Rep Power
    0

    Default

    Check out the Random class or the Math.random() method for generating the random numbers.

    Also check out Arrays.

    If your unsure as to how to make the loops, conditional statements, and flow of the program as well, it's probably best you start from the beginning.

    Mr. Beans

  6. #6
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    btw, its 3 months ago. I don't think his comming back...
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  7. #7
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default dang...

    hahaha... you're right... I didn't even notice that... yep... probably already got it solved by now. Oh, well... maybe it'll help somebody else.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  2. Help with random numbers
    By checkmylongboarding in forum New To Java
    Replies: 2
    Last Post: 01-12-2009, 06:47 AM
  3. Random numbers
    By jithan in forum Advanced Java
    Replies: 3
    Last Post: 06-14-2008, 03:04 PM
  4. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  5. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 03:56 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
  •