The specific compile time error in your class is the result of trying to call a method on a value which was declared as a primitive type.
Primitive types are not Object
s and thus do not have properties. Hence they do not have any methods.
You could either cast the primitive double
value to a primitive int
value,
double b = Math.sqrt(absoluteNumber) ;
int a = (int) b ;
or cast the double
to a Double
---using a Java feature called auto-boxing---in order to use the intValue
method of the Number
interface implemented by the Double
class:
double b = Math.sqrt(absoluteNumber) ;
int a = ( (Double) b ).intValue( ) ;
Another way is to use the valueOf
and intValue
methods of the Double
class:
double b = Math.sqrt(absoluteNumber) ;
int a = ( Double.valueOf(b) ).intValue( ) ;