为什么int,long没有最大的16进制数值?

同桌老王 2004-08-19 06:49:03
think in java如是说。
...全文
235 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkyy 2004-08-19
  • 打赏
  • 举报
回复
呵呵法律没有规定你可以找女朋友你都找了
holy_phoenix 2004-08-19
  • 打赏
  • 举报
回复
当然有啦
registered 2004-08-19
  • 打赏
  • 举报
回复

他没写不等于没有
int maxInt = 0x7FFFFFFF;// 32 bit
long maxLong = 0x7FFFFFFFFFFFFFFF; // 64 bit
同桌老王 2004-08-19
  • 打赏
  • 举报
回复
第三章


Literals
Ordinarily when you insert a literal value into a program the compiler knows exactly what type to make it. Sometimes, however, the type is ambiguous. When this happens you must guide the compiler by adding some extra information in the form of characters associated with the literal value. The following code shows these characters:
//: Literals.java

class Literals {
char c = 0xffff; // max char hex value
byte b = 0x7f; // max byte hex value
short s = 0x7fff; // max short hex value
int i1 = 0x2f; // Hexadecimal (lowercase)
int i2 = 0X2F; // Hexadecimal (uppercase)
int i3 = 0177; // Octal (leading zero)
// Hex and Oct also work with long.
long n1 = 200L; // long suffix
long n2 = 200l; // long suffix
long n3 = 200;
//! long l6(200); // not allowed
float f1 = 1;
float f2 = 1F; // float suffix
float f3 = 1f; // float suffix
float f4 = 1e-45f; // 10 to the power
float f5 = 1e+9f; // float suffix
double d1 = 1d; // double suffix
double d2 = 1D; // double suffix
double d3 = 47e47d; // 10 to the power
} ///:~

Hexadecimal (base 16), which works with all the integral data types, is denoted by a leading 0x or 0X followed by 0–9 and a–f either in upper or lower case. If you try to initialize a variable with a value bigger than it can hold (regardless of the numerical form of the value), the compiler will give you an error message. Notice in the above code the maximum possible hexadecimal values for char, byte,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
and short. If you exceed these, the compiler will automatically make the value an
~~~~~~~~~~
int and tell you that you need a narrowing cast for the assignment. You’ll know you’ve stepped over the line.
registered 2004-08-19
  • 打赏
  • 举报
回复
麻烦你把相关章节的内容贴出来取证一下

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧