What is happening right now is the compiler is seeing that you are trying to add a double
and a boolean
together using the +
operator, which it does not know how to do. One option is to use the below code:
System.out.println("" + money + isTrue);
The first String literal tells the compiler to add a String
and a double
, which the compiler can do successfully by implicitly converting the double
to a String
. The same thing happens with the boolean
.
Since String
is a class, and double
and boolean
are primitive types, casting does not work between the two like it would in C# (see here for more information on that).
This produces your expected output when run:
9999.99false