Results 1 to 4 of 4
  1. #1
    picky is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Red face (API)Randomized Problem ..please suggest me

    Hi,

    I'm very new to java and i have this weird problem for using java.util.Random.
    I have created a method in which the question specifically tells to use double as a parameter. What i did was

    public int Number(double end)
    {
    Random rand = new Random();
    int start = 0;

    int output= rand.nextInt( end - start+ 1) + start;
    return output;
    }


    But its not working. I need to find random number between 0-88.9 and the return value should be integer. Please help me.:confused:

  2. #2
    x2robbie2x is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    int output= rand.nextInt( end - start+ 1) + start;

    You're typing nextInt but the random is giving you a double =) there's your problem.

  3. #3
    picky is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    thanks for the reply but what should i do to fix it. I'm totally lost in it

    I have also tried this way

    int output= rand.nextDouble( end - start+ 1) + start;

    but its not working either. I guess nextDouble is for between 0 and 1.
    Last edited by picky; 02-12-2010 at 01:53 PM.

  4. #4
    x2robbie2x is offline Member
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    0

    Default

    I haven't had to input a double in a long time, but I'm guessing its nextDouble?

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2008, 05:24 AM
  2. Hello friends !! suggest me a project
    By Nishit in forum Advanced Java
    Replies: 7
    Last Post: 07-17-2008, 07:51 AM
  3. Please suggest me the correct approach!
    By rjuyal in forum Advanced Java
    Replies: 6
    Last Post: 05-05-2008, 02:54 PM
  4. Please suggest a database ?
    By Vinuraj in forum CLDC and MIDP
    Replies: 1
    Last Post: 01-14-2008, 08:48 AM
  5. Suggest me the best practise for accesing database by JSP page
    By saurabh.joshi in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 11-27-2007, 06:39 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
  •