Languages
[Edit]
EN

Java - get long max value

12 points
Created by:
Root-ssh
178260

Short solution:

Java Long max value is  9223372036854775807

 

Additionally short solution to get long min value:

Java Long min value is -9223372036854775808

 

1. Alternative solutions

Edit

This section contains different approaches that lets to get max Long value.

  • Using build-in Long.MAX_VALUE
  • Using math power e.g. (long) Math.pow(2, 63)
  • Using bit shifting e.g. -1L >>> 1
  • Using bit shifting and not e.g. ~0L >>> 1

Code example with above methods:

Output:

2. Long overflow example

Edit

Output: 

 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - numbers operations

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join