Here is a Java Program to Compute distance light travels using long variables
Output of Above Java Program
In 1000 days light will travel about 16070400000000 miles.
class Light { public static void main(String args[]) { int lightspeed; long days; long seconds; long distance; // approximate speed of light in miles per second lightspeed = 186000; days = 1000; // specify number of days here seconds = days * 24 * 60 * 60; // convert to seconds distance = lightspeed * seconds; // compute distance System.out.print("In " + days); System.out.print(" days light will travel about "); System.out.println(distance + " miles."); } }
Output of Above Java Program
In 1000 days light will travel about 16070400000000 miles.
thank you.,