Reputation: 738
Like C/C++ have the INT_MAX
macro (#include<limits.h>)
to set a variable to INFINITY.
I was wondering if there is a similar function/macro in JAVA. I want to set an integer variable to INFINITY.
Thanks in advance !!
Upvotes: 3
Views: 2713
Reputation: 2711
Java doesn't supports infinity in int type. The only way to represent an infinity number in Java is with the double type:
double infinity = Double.POSITIVE_INFINITY;
Look at here: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#POSITIVE_INFINITY
Upvotes: 0
Reputation: 1010
The static
MAX_VALUE variable of the Integer class is what you want.
Integer.MAX_VALUE
However, this isn't as useful in Java, since int
values in Java are 32 bits no matter what.
Go to the following web page to learn more about the Integer class:
https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html
Upvotes: 3