Results 1 to 2 of 2
- 11-23-2007, 08:24 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 4
- Rep Power
- 0
- 11-23-2007, 09:28 PM #2
((width/2) + (0.5-Math.random())*width)
Math.random returns a double — we know this is true because we can look up the method in the Math class api and see the return type specified in the first column of the table in the Methods Summary section.
So the expression
(0.5-Math.random())*width)
will evaluate to a double.
For precision the (width/2) term, which may be an int, is grouped into the same expression and the whole thing is cast to an int.
int x = the value over here must be an int so we cast the double expression to the lesser–precision int primitive data type. Going from higher to lower precision requires an explicit cast.
Similar Threads
-
I need help fixing my code.. or non code?
By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 10:12 PM -
java in cmd line :(
By Joe2003 in forum New To JavaReplies: 2Last Post: 02-01-2008, 08:51 AM -
line feed in CSV
By javaplus in forum New To JavaReplies: 2Last Post: 01-24-2008, 03:46 PM -
Reading in data from file line by line
By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM -
Generating Code Automatically Using Custom code Template In Eclipse
By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks