Results 1 to 4 of 4
- 10-10-2013, 02:24 AM #1
Member
- Join Date
- Oct 2013
- Posts
- 63
- Rep Power
- 0
Need help understanding how to use java data types such as int and doubles
Here's an example:
package rootscan;
public class Rootscan
{
public static void main(String[] args)
{
int x1
double x1root;
x1 = 2;
x1root = Math.sqrt(x1);
System.out.println(" the root of " + x1 + " is " + x1root);
I know that double has a size of 8 bytes or 64 bits but why did we use double in particular?
- 10-10-2013, 02:42 AM #2
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 13
Re: Need help understanding how to use java data types such as int and doubles
Because it has greater precision than float which is only 32 bits wide. For arbitrary
precision you can use BigDecimal and its supporting methods.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 10-10-2013, 02:53 AM #3
Member
- Join Date
- Oct 2013
- Posts
- 63
- Rep Power
- 0
Re: Need help understanding how to use java data types such as int and doubles
I think I kind of get it now, thanks!
- 10-10-2013, 10:51 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 26
Re: Need help understanding how to use java data types such as int and doubles
It's also because that's what the sqrt() method returns, and Java will put up a warning about loss of precision if you were to stick the result in a float.
Please do not ask for code as refusal often offends.
** This space for rent **
Similar Threads
-
Java Data Types ?!
By HearT.Hunt3r in forum New To JavaReplies: 4Last Post: 08-09-2011, 05:43 PM -
Understanding limitations of int data-type
By JONCOM in forum New To JavaReplies: 11Last Post: 01-30-2011, 10:57 PM -
primitive Data types
By Manfizy in forum New To JavaReplies: 2Last Post: 07-07-2009, 09:29 PM -
Primitive data types of Java
By Java Tip in forum Java TipReplies: 0Last Post: 03-28-2008, 08:29 PM
Bookmarks