谁能告诉我为什么我不能这样声明数组?
long[] powers = { 0, 0, 1, 7, 35, 155, 651, 2667, 10795, 43435,
174251, 698027, 2794155, 11180715, 44731051, 178940587,
715795115, 2863245995, 11453115051, 45812722347, 183251413675,
733006703275, 2932028910251, 11728119835307, 46912487729835,
187649967696555, 750599904340651, 3002399684471467};
编译器说 int 类型的文字超出范围。我也试过像这样把它投到很长的时间
long[] powers = { 0, 0, 1, 7, 35, 155, 651, 2667, 10795, 43435,
174251, 698027, 2794155, 11180715, 44731051, 178940587,
715795115, (long)2863245995, (long)11453115051, (long)45812722347, etc ...
但没有任何改变也尝试了像这样的 Long.valueOf(x)
其中 x 是编译器有问题的数字。
有什么想法吗?
提前致谢
最佳答案
普通数字在 java 中被视为 int
。追加大于Integer.MAX_VALUE
的L
来转换long
。
long[] powers = {..., 2863245995L, 11453115051L, ...};
根据 docs
An integer literal is of type
long
if it is suffixed with an ASCII letter L or l (ell); otherwise it is of typeint
.The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).
关于java - 在 java 中声明 long[] 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20175272/