Light travels 299 792 458 metres per second. Write LightYear with that value as an int constant SPEED_OF_LIGHT. Read a number of light-years (a double) and print:
- the seconds in a year (365 days) — an
int; SPEED_OF_LIGHT * secondsPerYearcomputed as anint(wrong: overflow);- the same product computed as a
long(cast one operand first); - the distance in km as a
double, 5. the same value cast tofloat, and 6. the whole number of billions of km (cast tolong).
For the input
1
the program prints
Seconds in a year: 31536000
int result (wrong): 1144840960
One light-year in metres: 9454254955488000
1.0 light-years in km: 9.454254955488E12
The same as a float: 9.454255E12
Whole billions of km: 9454