O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required