要计算光的传播距离,我们需要遵循基本公式来计算距离。
Distance = Speed x Time
这里,以下是参数-
speed = 186000; days = 365; seconds = days * 24 * 60 * 60;
上面,我们以一年为单位计算了时间-
days = 365; seconds = days * 24 * 60 * 60;
以下是计算光传播距离的完整示例-
public class Demo { public static void main(String[] args) { int speed; long days, seconds, dist; speed = 186000; days = 365; seconds = days * 24 * 60 * 60; dist = speed * seconds; System.out.print("Light travels: "+dist + " miles"); } }
输出结果
Light travels: 5865696000000 miles