Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)
edited by

Here’s my code below:

class LongTest {

   private static long increment;

   public static long generateNumber(){

       ++increment;

       return increment;

   }

}

It calls the 'generateNumber'method which will increment my long data type by 1. Can anyone tell me what I should do when it reaches its maximum limit? 

1 Answer

0 votes
by (19.7k points)

Even if you execute the function once per nanosecond, it’ll take around 292 years(refer here) for the long data type to be fully used up. Since Long.MAX_VALUE is 9,223,372,036,854,775,807. If the overflow happens, you can wrap it to Long.MIN_VALUE

 If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 3, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...