![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to calculate distance light travels
To calculate distance light travels, we need to follow the basic formulae to calculate distance.
Distance = Speed x Time
Here, the following are the parameters −
speed = 186000; days = 365; seconds = days * 24 * 60 * 60;
Above, we calculated the time in seconds for an year −
days = 365; seconds = days * 24 * 60 * 60;
The following is the complete example to calculate distance light travels −
Example
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"); } }
Output
Light travels: 5865696000000 miles
Advertisements