I am struggling with a problem, which I can't understand why it doesn't work. How do I pass a variable through the double obj
and convert to int
?
Why does it not work in the top code snippet, but it works in the bottom code snippet below the line?
The only difference seems to be adding an extra variable, which is also typed as a double
?
//Converting double to int using helper
//This doesn't work- gets error message
//Cannot invoke intValue() on the primitive type double
double doublehelpermethod = 123.65;
double doubleObj = new Double( doublehelpermethod);
System.out.println("The double value is: "+ doublehelpermethod.intValue());
//--------------------------------------------------------------------------
//but this works! Why?
Double d = new Double(123.65);
System.out.println("The double object is: "+ doubleObj);