Lesson+05


 * Lesson #05: Mixed Data Types, Casting, and Constants - Julian**

When different data types are combined in a calculation, a loss of information is possible. double k = j; ||< k equals 5.0 || int k = j; ||||< Error: java refuses to compile for data loss || To work around this, a programmer can cast a variable:
 * < int j = 5;
 * < double j = 3.5;

double j = 3.5; int k = (int)j; System.out.println(k);//returns 3

Casting applies to the item directly after it: (double) 4 +3 -> 4.0 + 3 -> 7.0 (int)(7/2) +3.0 -> 3 + 3.0 -> 6.0

Constants work just like variables, except they cannot be changed. Conventionally, constants are named with capital letters. final double PI = 3.1415962;