Category : Java | Sub Category : Data type, Variable and Arays | By Prasad Bonam Last updated: 2020-09-28 14:20:10 Viewed : 386
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: