gpt4 book ai didi

java - 在有关虚拟地址的java程序中使用biginteger

转载 作者:行者123 更新时间:2023-12-01 11:27:51 24 4
gpt4 key购买 nike

也许由于我对biginteger的使用有限而产生误解,但我有一个程序需要获取用户输入的页面大小和虚拟地址并计算偏移量和虚拟页面。我可以毫无问题地进行计算,但是当比较输入的迭代器时,虚拟地址(4294967295)的必要值超出范围。我试图将这个数字声明为一个大整数,但相同的运算符似乎不起作用。我是否必须忘记零并找到一种方法来表示输入小于或等于该数字?这是代码:

public class VAddress {

public static void main(String args[]){

BigInteger max = new BigInteger("4294967295");

Scanner PAGEinput = new Scanner(System.in);
Scanner ADDinput = new Scanner(System.in);

System.out.println("Please Enter the system page size (between 512 and 16384):");
int page = PAGEinput.nextInt();

System.out.println("Please Enter the Virtual Address: ");
int address = ADDinput.nextInt();

if(page >= 512 && page <= 16384){
if( address >= 0 && address <= max){

}
}



}

}

最佳答案

BigInteger address = new BigInteger(address);
if(page >= 512 && page <= 16384){
if(address.compareTo(new BigInteger("0"))>=0 && address.compareTo(max)<=0){

}
}

关于java - 在有关虚拟地址的java程序中使用biginteger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30671294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com