A long bigger than Long.MAX_VALUE

That method can’t return true. That’s the point of Long.MAX_VALUE. It would be really confusing if its name were… false. Then it should be just called Long.SOME_FAIRLY_LARGE_VALUE and have literally zero reasonable uses. Just use Android’s isUserAGoat, or you may roll your own function that always returns false. Note that a long in memory takes a fixed number of bytes. From Oracle: long: The long data type is a … Read more

How to implement infinity in Java?

double supports Infinity double inf = Double.POSITIVE_INFINITY; System.out.println(inf + 5); System.out.println(inf – inf); // same as Double.NaN System.out.println(inf * -1); // same as Double.NEGATIVE_INFINITY Add titleHow to implement infinity in Java? double supports Infinitydouble inf = Double.POSITIVE_INFINITY; System.out.println(inf + 5); System.out.println(inf – inf); // same as Double.NaN System.out.println(inf * -1); // same as Double.NEGATIVE_INFINITY printsInfinity … Read more

Division of integers in Java

Converting the output is too late; the calculation has already taken place in integer arithmetic. You need to convert the inputs to double: System.out.println((double)completed/(double)total); Note that you don’t actually need to convert both of the inputs. So long as one of them is double, the other will be implicitly converted. But I prefer to do both, for symmetry.