-1

How can I assign value of light year in meters in java to datatype, it seems it is too long.

For example:- 9,460,730,777,119,564 is value in mtrs for 1 light year

Rahul Singh
  • 781
  • 11
  • 27

2 Answers2

2

The Long datatype in standard java 2^63-1 digits, so the speed of light in meters should fit

bWilliamson
  • 174
  • 1
  • 9
1

You can use Long for it.

Long lightYearsInMeters = new Long("9460730777119564");
System.out.println(lightYearsInMeters);
Sujit kumar
  • 131
  • 10