# int/double

• 01-11-2013, 06:38 AM
Droid_X
int/double
What is the difference? If I use this to calculate the square root of a number using Math.pow(), I get a decimal. I am guessing it has to do with int/double.

Code:

```class hi{         public static double squareRoot(int a){                 return Math.pow(a, 0.5);         }         public static void main(String args[]){                 System.out.println(squareRoot(16));         } }```
• 01-11-2013, 06:41 AM
Wnt2bsleepin
Re: int/double
Data Types

Basically, a double is a floating point number i.e: 2.3
An int is a whole number integer i.e: 5
• 01-11-2013, 06:43 AM
Droid_X
Re: int/double
Ah ok.

So how would I make it return an int?

If I replace this:

Code:

`public static double squareRoot(int a)`
with:

Code:

`public static int squareRoot(int a)`

I get an error.
• 01-11-2013, 06:48 AM
Wnt2bsleepin
Re: int/double
Math.pow

See if you can figure out why it won't let you return an int.
• 01-11-2013, 06:51 AM
Droid_X
Re: int/double
Oh, Math.pow only takes a double. I just converted the double to an int.

Code:

```class apples{         public static double squareRoot(double a){                 return Math.pow(a, 0.5);         }         public static void main(String args[]){                 int num = (int)squareRoot(16);                 System.out.println(num);         } }```
• 01-11-2013, 06:57 AM
Wnt2bsleepin
Re: int/double
Just a small correction, it returns a double. You can convert an int to a double easily, the reverse is not as easy. That is why it lets you give it an int as an option because it converts it to an integer.

Code:

```                double a = 5.4;                 int b = (int)a;                                 int c = 6;                 double d = c;```