- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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

- Related Questions & Answers
- C program to calculate distance between two points
- Methods to Calculate the Illumination of Light
- C program to calculate distance between three points in 3D
- How to calculate mahalanobis distance in R?
- Java program to calculate mode in Java
- Java program to calculate student grades
- Java program to calculate the percentage
- Java Program to calculate Compound Interest
- Java Program to Calculate Standard Deviation
- Java Program to Calculate Simple Interest
- Java Program to Calculate the Compound Interest
- Calculate distance and duration between two places using google distance matrix API in Python?
- Java program to calculate mean of given numbers
- Java program to calculate Body Mass Index (BMI)
- Java Program to calculate area of a Tetrahedron

Advertisements