Why, we have to use Long.MAX_VALUE?
Why Long.MAX_VALUE
Resolved
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Jason
2 May 2020, 18:59solution
well say you initialized a variable that you are going to use for a comparison looking for smaller numbers in a loop and you initialized it with a really high number for the sake of it being WAY higher than probable initial comparisons and then your guess wasn't big enough and now your code doesn't work properly because you initial guess is actually smaller than number you actually get. Well Long.MAX_VALUE will just automatically give the highest number possibly achievable by a Long there making it impossible for your initial number to be too small, ever. And, if you go over this number then you need something that can store bigger numbers then Long.
+2
Sela
3 August 2020, 18:53
you do not have use Long.MAX_VALUE. better to read ones from FileInputStream and store the byte number to minimum variable and then start to read in loop storing the actual byte number in temporary variable. still in loop compare values of both variables and update minimum variable.
+1
Neil Hainer
15 February 2021, 12:42
You can use Integer.MAX_VALUE.
0