简体   繁体   English

与Java中的C / C ++ INT_MAX宏类似

[英]What is the akin to C/C++ INT_MAX macro in Java

Like C/C++ have the INT_MAX macro (#include<limits.h>) to set a variable to INFINITY. 像C / C ++一样,可以使用INT_MAX(#include<limits.h>)将变量设置为INFINITY。 I was wondering if there is a similar function/macro in JAVA. 我想知道JAVA中是否有类似的功能/宏。 I want to set an integer variable to INFINITY. 我想将整数变量设置为INFINITY。

Thanks in advance !! 提前致谢 !!

The static MAX_VALUE variable of the Integer class is what you want. 您想要的是Integer类的static MAX_VALUE变量。

Integer.MAX_VALUE

However, this isn't as useful in Java, since int values in Java are 32 bits no matter what. 但是,这在Java中没什么用,因为Java中的int值无论如何都是32位。

Go to the following web page to learn more about the Integer class: 转到以下网页以了解有关Integer类的更多信息:

https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html

Java doesn't supports infinity in int type. Java不支持int类型的无穷大。 The only way to represent an infinity number in Java is with the double type: 在Java中表示无限数的唯一方法是使用double类型:

double infinity = Double.POSITIVE_INFINITY;

Look at here: https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#POSITIVE_INFINITY 在这里查看: https : //docs.oracle.com/javase/7/docs/api/java/lang/Double.html#POSITIVE_INFINITY

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM