作业帮 > 综合 > 作业

java中System.out.print(("short".toString().hashCode() & Integ

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/07/19 07:09:56
java中System.out.print(("short".toString().hashCode() & Integer.MAX_VALUE )% 3);的意思
System.out.print(("short".toString().hashCode() & Integer.MAX_VALUE )% 3);的意思是什么?
.hashCode() 是将short转化成某一固定的数字吗?
& Integer.MAX_VALUE是什么意思?
%3是除以3,有求余数的意思吗?
java中System.out.print((
package test;

public class TestAgain {

\x05public static void main(String[] args) {
\x05\x05
\x05\x05int a = "short".toString().hashCode();//2
\x05\x05int b = Integer.MAX_VALUE;//2147483647
\x05\x05System.out.println(("short".toString().hashCode() & Integer.MAX_VALUE )% 3);
\x05\x05System.out.println((a & b) % 3);
\x05}
}
hashCode()是Object类的一个方法,hashCode() Returns a hash code value for the object.

Integer.MAX_VALUE表示int类型能够表示的最大值,

&是按位与运算符
比如a&b表示把a和b进行二进制的按位与运算
比如8&10,其中8的二进制是0000 1000,而10的二进制是0000 1010,因此
      0000 1000(十进制8)
   & 0000 1010(10进制10)
结果为0000 1000(就是10进制的8)
因此8&10的结果为8
与的计算规则是,如果两个数都都为真(或为1),其结果为真,如果两位数中有一位为假(或为0)者结果为假

上面的程序就是2 和2147483647按位与然后再模3取余.