-
Notifications
You must be signed in to change notification settings - Fork 7
IB Java Developer 线上面试
CoderDream edited this page May 5, 2022
·
1 revision
/**
* 打印32位和64位无符号数
*
*/
@Test
public void test3() {
BigInteger bigInteger = new BigInteger("2");
int ind = 0;
int index = 63;
for(int i = 0; i < index; i++) {
ind = i + 2;
bigInteger = bigInteger.multiply(new BigInteger("2"));
System.out.println(ind + " : " + bigInteger);
}
}
/**
* 问:如果遍历 32 位无符号数需要 1 毫秒,那遍历 64 位无符号数需要多长时间?
* 答:7 周
*/
@Test
public void test4() {
BigInteger bigInteger64 = new BigInteger("18446744073709551616");
BigInteger bigInteger32 = new BigInteger("4294967296");
BigInteger bigIntegerResult = bigInteger64.divide(bigInteger32);
// 秒
bigIntegerResult = bigIntegerResult.divide(new BigInteger("1000"));
// 小时
bigIntegerResult = bigIntegerResult.divide(new BigInteger("3600"));
// 天
bigIntegerResult = bigIntegerResult.divide(new BigInteger("24"));
// 周
bigIntegerResult = bigIntegerResult.divide(new BigInteger("7"));
System.out.println("耗时:" + bigIntegerResult + " 周");
}
/**
* 问:运行完成后,x的值为多少?
* 答: 34
*/
@Test
public void test5() {
int x = 1;
int y = 1;
int z = 1000;
while (x < 25) {
z = x;
x = x + y;
y = z;
}
System.out.println(x);
}