Write a program to compute distance light travel in 1000 days using long variables.

Category : Java | Sub Category : Data type, Variable and Arays | By Runner Dev Last updated: 2020-09-28 14:20:10 Viewed : 217


(Data type, Variable and Arays)

Write a program to compute distance light travel in 1000 days using long variables.

DESCRIPTION: This program calculate the speed of light in 1000 days. We take long variable to store the speed of light because inttype is not large enough to hold the desire value. The range of a long is quite large. This makes it useful whrn big whole numbers are needed.

 /**

 *

 * Write a program to compute distance light travel in 1000 days using long

 * variables.

 */

Public class Light { // This line daclare a new class & the class defination is start.

     public static void main(String a[]) { // This line begins the main() method.

         int lightspeed; // daclare a integer name lightspeed.

         long days; // daclare a variable days of datatype long.

         long seconds, distance;

         lightspeed = 186000; // aproximate speed of light n miles per second.

         days = 1000; // specify number of days.

         seconds = days * 24 * 60 * 60; // convert to seconds.

         distance = lightspeed * seconds; // compute distance

         System.out.print("In " + days);

         System.out.print(" days lightwill travel about ");

          System.out.println(distance + " miles."); // print distance in miles.

     }

}

OUTPUT:


  

Search
Related Articles

Leave a Comment:
ioditle
at 2022-04-04 23:07:34
Achat Lioresal Faghvh [url=https://oscialipop.com]Cialis[/url] Zvuvjg <a href=https://oscialipop.com>Cialis</a> Dczfzs rheumatologist https://oscialipop.com - Cialis