long
is a signed 64-bit type.
long
type is useful when an int
type is not large enough to hold the value.
public class Main {
public static void main(String args[]) {
long lightspeed;
long days;
long seconds;
long distance;
lightspeed = 300000;
days = 365;
seconds = days * 24 * 60 * 60; // convert to seconds
distance = lightspeed * seconds; // compute distance
System.out.print("In " + days);
System.out.print(" days light will travel about ");
System.out.println(distance + " km.");
}
}
This program generates the following output:
In 365 days light will travel about 9460800000000 km.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |