Results 1 to 2 of 2
- 11-23-2007, 09:24 PM #1Member
- Join Date
- Nov 2007
- Rep Power
- 11-23-2007, 10: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
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.
- By MrHuggykins in forum New To JavaReplies: 1Last Post: 03-19-2008, 11:12 PM
- By Joe2003 in forum New To JavaReplies: 2Last Post: 02-01-2008, 09:51 AM
- By javaplus in forum New To JavaReplies: 2Last Post: 01-24-2008, 04:46 PM
- By bluekswing in forum New To JavaReplies: 1Last Post: 10-02-2007, 12:19 AM
- By JavaForums in forum EclipseReplies: 1Last Post: 04-26-2007, 03:52 PM