gpt4 book ai didi

java - 长范围值的查找

转载 作者:行者123 更新时间:2023-12-02 11:25:29 24 4
gpt4 key购买 nike

我在查找值中查找长整型值并返回相应的值。为了不出现任何与值相关的错误,我将所有值设置为 Long 类型。

这是我的代码

package RestClient;

public class Range {

public static Long upper;
public static Long value;

public Range(Long i, Long j) {
Range.upper = i;
Range.value = j;
}

}



package RestClient;

import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

public class Rangelookup {

public static String Lookup(Long key) {

NavigableMap<Long, Range> map = new TreeMap<Long, Range>();
map.put(5045076263000000000L, new Range(5045076263249899999L, 507866L));
map.put(5045076263249900000L, new Range(5045076263249999999L, 507866L));
map.put(5045076263250000000L, new Range(5045076263499899999L, 507868L));
map.put(5045076263499900000L, new Range(5045076263499999999L, 507868L));
map.put(5045076263500000000L, new Range(5045076263749899999L, 507867L));
map.put(5045076263749900000L, new Range(5045076263749999999L, 507867L));
map.put(5045076263750000000L, new Range(5045076263999899999L, 507869L));
map.put(5045076263999900000L, new Range(5045076263999999999L, 507869L));
map.put(5045075892250000000L, new Range(5045075892499899999L, 507867L));
map.put(5045075892499900000L, new Range(5045075892499999999L, 507867L));
map.put(5045075892000000000L, new Range(5045075892249899999L, 507869L));
map.put(5045075892249900000L, new Range(5045075892249999999L, 507869L));

String output = "";
Map.Entry<Long, Range> entry = map.floorEntry(key);
if (entry == null) {

output = "No Entry Found";

} else if (key <= entry.getValue().upper) {

output = entry.getValue().value.toString();

} else {

output = "No Entry Found";

}

System.out.println(output);
return output;

}

public static void main(String[] args) {

Lookup(5045076263249899985L);

}

}

请问为什么它没有返回任何值?为什么会出现“找不到条目”的情况?

我可以知道我做错了什么吗?

最佳答案

找到的条目是这个:

map.put(5045076263000000000L, new Range(5045076263249899999L, 507866L));

但是上限值5045075892249999999小于查找键5045076263249899985:

5045075892249999999
<
5045076263249899985

因此您会得到“找不到条目”

关于java - 长范围值的查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49670602/

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