3. Operators and Assignments

3.1 The following program will compile and run without errors:
 // Filename: Sunlight.java public class Sunlight { public static void main(String[] args) { // Distance from sun (150 million kilometers) /* The max value for int is 2147483647, so using int here will work. */ int kmFromSun = 150000000; // Again, using int for this value is OK. int lightSpeed = 299792458; // Meters per second // Convert distance to meters. /* The result of this equation will not fit in an int. Let's use a long instead. We need to ensure that the values that are multiplied really are multiplied using long data types, not multiplied as int data types and later converted to long. The L suffix on the 1000L integer literal ensures this. The ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.