Results 1 to 4 of 4
- 02-12-2010, 01:27 PM #1
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
(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:
- 02-12-2010, 01:47 PM #2
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
int output= rand.nextInt( end - start+ 1) + start;
You're typing nextInt but the random is giving you a double =) there's your problem.
- 02-12-2010, 01:49 PM #3
Member
- Join Date
- Feb 2010
- Posts
- 2
- Rep Power
- 0
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.
- 02-12-2010, 01:52 PM #4
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Can some one suggest me, which is the best framework to develop desktop application?
By nanaji in forum Advanced JavaReplies: 7Last Post: 12-10-2008, 05:24 AM -
Hello friends !! suggest me a project
By Nishit in forum Advanced JavaReplies: 7Last Post: 07-17-2008, 07:51 AM -
Please suggest me the correct approach!
By rjuyal in forum Advanced JavaReplies: 6Last Post: 05-05-2008, 02:54 PM -
Please suggest a database ?
By Vinuraj in forum CLDC and MIDPReplies: 1Last Post: 01-14-2008, 08:48 AM -
Suggest me the best practise for accesing database by JSP page
By saurabh.joshi in forum JavaServer Pages (JSP) and JSTLReplies: 3Last Post: 11-27-2007, 06:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks