0

我想从属性文件中读取值作为一系列值。我的任务是,根据获得的分数计算结果。例如,点是,

<100 : some result.
101 - 110 : Some result.
111 - 120 : Some result.
121 - 130 : some result.
.....
.....
991 - 1000 : some result.
>1000 : some result.

有什么方法可以从属性文件中存储和获取结果,而不是将 [key,value] 对从 1 放置到 1000,因为我也可能得到浮点值?我应该为所有可能的条件编写 if else 语句吗?

4

1 回答 1

0

我会使用一个数组

String[] results = "<100,<100,<100,<100,<100,<100,<100,<100,<100,<100,result101-110,result111-120, etc".split(",");

String result = results[(value-1)/10];

或者,如果范围不同,您可以使用 NavigableMap

NavigableMap<Double, String> map = ...
String result = map.higherEntry(value).getValue();

在这种情况下,格式可以是upper-limit result

100 some result.
110 Some result.
120 Some result.
130 some result.
.....
.....
1000 Some result.
Infinity some result.
于 2012-08-08T14:22:05.820 回答